想要实现:
即,label文字的上下和左右,都和边框间距8px=4point
swift uilabel text padding
ios – Adding space/padding to a UILabel (Swift) – Stack Overflow
How do you add inset to UILabel (iOS Swift)? – Stack Overflow
ios – Inset text in UILabel from left – Stack Overflow
最后换成TextView,然后加上textContainerInset即可:
self.systemNoticeTextView = UITextView() self.systemNoticeTextView.text = notifMsg.notice self.systemNoticeTextView.textAlignment = NSTextAlignment.Left self.systemNoticeTextView.textColor = ColorSystemNoticeText self.systemNoticeTextView.font = FontSystemNotice self.systemNoticeTextView.backgroundColor = ColorSystemNoticeBackground self.systemNoticeTextView.layer.borderWidth = 1 self.systemNoticeTextView.layer.borderColor = ColorSystemNoticeBackground.CGColor self.systemNoticeTextView.layer.cornerRadius = 2 self.systemNoticeTextView.editable = false self.systemNoticeTextView.selectable = false self.systemNoticeTextView.scrollEnabled = false self.systemNoticeTextView.textContainerInset = InsetSystemNotice self.contentView.addSubview(self.systemNoticeTextView) constrain(systemNoticeTextView) {systemNoticeLabel in systemNoticeLabel.top == systemNoticeLabel.superview!.top + PaddingYMessageTVC systemNoticeLabel.centerX == systemNoticeLabel.superview!.centerX systemNoticeLabel.bottom == systemNoticeLabel.superview!.bottom systemNoticeLabel.width <= systemNoticeLabel.superview!.width – (2 * (WidthAvatarPadding + SizeAvatarImage + BubbleArrowWidth)) } |
效果:
转载请注明:在路上 » [已解决]swift中如何控制Label中字体与边框的间距