UIFont中boldSystemFontOfSize和systemFontOfSize的区别

 


UIFont 的下列方法:

//系统的默认方法
systemFontOfSize

// 字体  bold:醒目的,雄浑的,突出的,使用后会加粗字体
boldSystemFontOfSize

// 字体为斜体 italic: 斜体,斜体字
italicSystemFontOfSize


学自:渊源♂

转载于:https://my.oschina.net/codeismygirl/blog/657159

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在iOS开发,实现文作文方框样式布局可以通过以下步骤实现: 1. 创建一个UIView作为方框容器,设置其背景色和边框样式。 2. 创建UILabel作为方框的文本容器,设置其行数、字体、颜色等属性,然后将其添加到方框容器。 3. 根据文作文的排版要求,使用NSAttributedString来设置UILabel的文本,包括字号、行间距、字间距等。 4. 根据文本内容计算UILabel的高度,并根据高度调整方框容器的高度。 示例代码: ```swift // 创建方框容器 let containerView = UIView(frame: CGRect(x: 20, y: 100, width: 300, height: 300)) containerView.backgroundColor = UIColor.white containerView.layer.borderWidth = 1 containerView.layer.borderColor = UIColor.black.cgColor self.view.addSubview(containerView) // 创建文本容器 let label = UILabel(frame: CGRect(x: 10, y: 10, width: 280, height: 20)) label.numberOfLines = 0 label.font = UIFont.systemFont(ofSize: 16) label.textColor = UIColor.black containerView.addSubview(label) // 设置文本内容 let text = "这是一篇文作文,要求使用方框样式进行排版。" let attributedString = NSMutableAttributedString(string: text) let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 8 paragraphStyle.alignment = .justified let range = NSRange(location: 0, length: text.count) attributedString.addAttribute(.font, value: UIFont.systemFont(ofSize: 16), range: range) attributedString.addAttribute(.paragraphStyle, value: paragraphStyle, range: range) label.attributedText = attributedString // 计算文本高度并调整方框容器高度 let size = label.sizeThatFits(CGSize(width: 280, height: CGFloat.greatestFiniteMagnitude)) label.frame.size.height = size.height containerView.frame.size.height = size.height + 20 ``` 在这个示例,我们创建了一个300x300的方框容器,并在其添加了一个UILabel作为文本容器。我们使用NSAttributedString来设置UILabel的文本,包括字号、行间距和字间距等。最后,我们计算文本高度并调整方框容器高度,使得文本能够完整地显示在方框

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值