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

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

快速使用屬性字符串使文本加粗

快速使用屬性字符串使文本加粗

iOS
人到中年有點(diǎn)甜 2019-11-12 10:59:18
我有這樣的字符串var str = "@text1 this is good @text1"現(xiàn)在,text1用另一個(gè)字符串代替t 1。我可以替換文本,但不能將其加粗。我想將新字符串加粗t 1,這樣最終輸出將是:@t 1這很好@t 1我該怎么做?我看到的所有示例都在Objective-C中,但是我想在Swift中完成。提前致謝。
查看完整描述

3 回答

?
皈依舞

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

如果您使用的是本地化字符串,則可能無(wú)法始終依靠粗體字符串作為句子的結(jié)尾。如果是這種情況,則可以很好地進(jìn)行以下操作:


例如查詢“ blah”與任何項(xiàng)目都不匹配


/* Create the search query part of the text, e.g. "blah". 

   The variable 'text' is just the value entered by  the user. */

let searchQuery = "\"\(text)\""


/* Put the search text into the message */

let message = "Query \(searchQuery). does not match any items"


/* Find the position of the search string. Cast to NSString as we want

   range to be of type NSRange, not Swift's Range<Index> */

let range = (message as NSString).rangeOfString(searchQuery)


/* Make the text at the given range bold. Rather than hard-coding a text size,

   Use the text size configured in Interface Builder. */

let attributedString = NSMutableAttributedString(string: message)

attributedString.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(label.font.pointSize), range: range)


/* Put the text in a label */

label.attributedText = attributedString


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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