第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在iOS Swift中為圖像添加文本?

如何在iOS Swift中為圖像添加文本?

一只名叫tom的貓 2019-08-16 16:30:14
如何在iOS Swift中為圖像添加文本?我已經(jīng)環(huán)顧四周,并沒有成功地弄清楚如何拍攝文字,將其疊加在圖像上,然后將兩者合并為一個(gè)UIImage。我使用我能想到的搜索字詞已經(jīng)讓Google筋疲力盡了,所以如果有人有解決方案或者至少提示他們可以指出它會(huì)非常感激。
查看完整描述

3 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊

我的簡(jiǎn)單方案:

func generateImageWithText(text: String) -> UIImage{
    let image = UIImage(named: "imageWithoutText")!

    let imageView = UIImageView(image: image)
    imageView.backgroundColor = UIColor.clearColor()
    imageView.frame = CGRectMake(0, 0, image.size.width, image.size.height)

    let label = UILabel(frame: CGRectMake(0, 0, image.size.width, image.size.height))
    label.backgroundColor = UIColor.clearColor()
    label.textAlignment = .Center
    label.textColor = UIColor.whiteColor()
    label.text = text    UIGraphicsBeginImageContextWithOptions(label.bounds.size, false, 0);
    imageView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    label.layer.renderInContext(UIGraphicsGetCurrentContext()!)
    let imageWithText = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext();

    return imageWithText}


查看完整回答
反對(duì) 回復(fù) 2019-08-16
  • 3 回答
  • 0 關(guān)注
  • 1022 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)