首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    IOS 改变字体样式 **

    1 import UIKit 2 import CoreText 3 4 class ViewController:UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 // Do any additional setup after loading the view, typically from a nib. 9 10 let label = UILabel(frame:CGRect(x:10, y:60, width:300, height:40)) 11 let string = NSMutableAttributedString(string:“Interactive tutorials for Xcode”) 12 13 let font = CTFontCreateWithName(“CourierNewPSBoldMT” as CFString?, 22, nil) 14 string.addAttribute(kCTFontAttributeName as String, value:font, range:NSRange(location:0, length:11)) 15 16 var number = 3 17 let cfNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberType.sInt8Type, &number) 18 string.addAttribute(kCTStrokeWidthAttributeName as String, value:cfNumber!, range: NSMakeRange(12, 9)) 19 20 let italicFont = UIFont.italicSystemFont(ofSize:14) 21 let fontValue = CTFontCreateWithName(italicFont.fontName as CFString?, 14, nil) 22 string.addAttribute(kCTFontAttributeName as String, value:fontValue, range: NSRange(location:22, length:3)) 23 24 string.addAttribute(kCTUnderlineStyleAttributeName as String, value:NSNumber(value:1), range: NSRange(location:26, length:5)) 25 26 label.attributedText = string 27 self.view.addSubview(label) 28 } 29 }

    03

    扫码

    添加站长 进交流群

    领取专属 10元无门槛券

    手把手带您无忧上云

    扫码加入开发者社群

    相关资讯

    热门标签

    活动推荐

      运营活动

      活动名称
      广告关闭
      领券