【问题标题】:Add UILabel to image将 UILabel 添加到图像
【发布时间】:2014-10-31 17:55:19
【问题描述】:

我正在创建一个图像,然后将其保存到用户的相机胶卷中。我想在图像中添加一些文字。我应该将字符串添加到 UILabel 然后将其转换为图像吗?

你有什么建议?谢谢。 (我正在使用 Swift)

    let bottomImage = UIImage(named: "Image1.png")
    let topImage = UIImage(named: "Image2.png")
    let anotherImage = UIImage(named: "Image3.png")

    let newSize = CGSizeMake(2480, 3508)
    UIGraphicsBeginImageContext(newSize)

    bottomImage?.drawInRect(CGRectMake(0, 0, newSize.width/2, 500))
    topImage?.drawInRect(CGRectMake(newSize.width/2, 0, newSize.width/2, 500), blendMode: kCGBlendModeNormal, alpha: 0.8)
    anotherImage?.drawInRect(CGRectMake(newSize.width/2, 500, newSize.width/2, 500), blendMode: kCGBlendModeNormal, alpha: 0.8)

    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()


    UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)

【问题讨论】:

    标签: ios swift uiimage uilabel


    【解决方案1】:

    【讨论】:

    • 如何将字符串添加到 NSAttributedString?
    • 我正在尝试使用下面的代码更改字体,但显示了一条错误消息。 let textFont = [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)] let title = NSAttributedString(string: titleValue) let title = NSAttributedString(string: titleValue, attributes: textFont) "调用中的额外参数'字符串'
    • 对于attributes,你想传递一个字典,所以我认为它的快速版本是attributes: [NSFontAttributeName : textFont]。
    • 我已将其更新为以下let title = NSAttributedString(string: titleValue, attributes: [NSFontAttributeName : textFont]) 并且仍然有相同的消息。
    猜你喜欢
    • 2011-06-01
    • 2012-12-05
    • 2015-03-29
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多