改變textview或lab等多行字體的大小與顏色等變化

self.textView= [[UITextViewalloc]initWithFrame:CGRectMake(15,100,self.view.frame.size.width-40,40)];

self.textView.showsVerticalScrollIndicator=NO;

self.textView.contentInset=UIEdgeInsetsMake(-5,0,0,0);

self.textView.delegate=self;

[self.viewaddSubview:self.textView];

self.textView.attributedText=? [selftwoFontWithStr1:@"ceshisa"TwoFontWithStr2:@"fdfvfghjghjfghfghjghghghjkldsa"font1:[UIFontsystemFontOfSize:18.f]font2:[UIFontsystemFontOfSize:12.f]color1:[UIColorredColor]color2:[UIColorblueColor]];

- (NSMutableAttributedString*)twoFontWithStr1:(NSString* )str1 TwoFontWithStr2:(NSString*)str2 font1:(UIFont*)font1 font2:(UIFont*)font2 color1:(UIColor*)color1 color2:(UIColor*)color2{

NSIntegerlen1 = str1.length;

NSIntegerlen2 = str2.length;

NSString* allStr = [NSStringstringWithFormat:@"%@\n%@",str1,str2];

NSIntegerlenAll = allStr.length;

NSLog(@"總字符%@,長度1%ld,長度2%ld,長度總%ld",allStr,len1,len2,lenAll);

NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStylealloc]init];

paragraphStyle.lineSpacing= -20;

paragraphStyle.alignment=NSTextAlignmentCenter;

NSDictionary* dic =@{NSParagraphStyleAttributeName:paragraphStyle};

NSMutableAttributedString*str = [[NSMutableAttributedStringalloc]initWithString:allStrattributes:dic];

[straddAttribute:NSFontAttributeNamevalue:font1range:NSMakeRange(0, len1)];

[straddAttribute:NSForegroundColorAttributeNamevalue:color1range:NSMakeRange(0, len1)];

[straddAttribute:NSFontAttributeNamevalue:font2range:NSMakeRange(len1 +1, len2)];

[straddAttribute:NSForegroundColorAttributeNamevalue:color2range:NSMakeRange(len1 +1, len2)];

returnstr;

}

// 通過改變屬性值來改變對應的字體大小顏色等柒巫,同事也可以增加字符串或者獲取一段字符串中的一段字符進行修改

// Predefined character attributes for text. If the key is not present in the dictionary, it indicates the default value described below.

UIKIT_EXTERNNSAttributedStringKeyconstNSFontAttributeNameNS_AVAILABLE(10_0,6_0);// UIFont, default Helvetica(Neue) 12

UIKIT_EXTERNNSAttributedStringKeyconstNSParagraphStyleAttributeNameNS_AVAILABLE(10_0,6_0);// NSParagraphStyle, default defaultParagraphStyle

UIKIT_EXTERNNSAttributedStringKeyconstNSForegroundColorAttributeNameNS_AVAILABLE(10_0,6_0);// UIColor, default blackColor

UIKIT_EXTERNNSAttributedStringKeyconstNSBackgroundColorAttributeNameNS_AVAILABLE(10_0,6_0);// UIColor, default nil: no background

UIKIT_EXTERNNSAttributedStringKeyconstNSLigatureAttributeNameNS_AVAILABLE(10_0,6_0);// NSNumber containing integer, default 1: default ligatures, 0: no ligatures

UIKIT_EXTERNNSAttributedStringKeyconstNSKernAttributeNameNS_AVAILABLE(10_0,6_0);// NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.

UIKIT_EXTERNNSAttributedStringKeyconstNSStrikethroughStyleAttributeNameNS_AVAILABLE(10_0,6_0);// NSNumber containing integer, default 0: no strikethrough

UIKIT_EXTERNNSAttributedStringKeyconstNSUnderlineStyleAttributeNameNS_AVAILABLE(10_0,6_0);// NSNumber containing integer, default 0: no underline

UIKIT_EXTERNNSAttributedStringKeyconstNSStrokeColorAttributeNameNS_AVAILABLE(10_0,6_0);// UIColor, default nil: same as foreground color

UIKIT_EXTERNNSAttributedStringKeyconstNSStrokeWidthAttributeNameNS_AVAILABLE(10_0,6_0);// NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)

UIKIT_EXTERNNSAttributedStringKeyconstNSShadowAttributeNameNS_AVAILABLE(10_0,6_0);// NSShadow, default nil: no shadow

UIKIT_EXTERNNSAttributedStringKeyconstNSTextEffectAttributeNameNS_AVAILABLE(10_10,7_0);// NSString, default nil: no text effect

UIKIT_EXTERNNSAttributedStringKeyconstNSAttachmentAttributeNameNS_AVAILABLE(10_0,7_0);// NSTextAttachment, default nil

UIKIT_EXTERNNSAttributedStringKeyconstNSLinkAttributeNameNS_AVAILABLE(10_0,7_0);// NSURL (preferred) or NSString

UIKIT_EXTERNNSAttributedStringKeyconstNSBaselineOffsetAttributeNameNS_AVAILABLE(10_0,7_0);// NSNumber containing floating point value, in points; offset from baseline, default 0

UIKIT_EXTERNNSAttributedStringKeyconstNSUnderlineColorAttributeNameNS_AVAILABLE(10_0,7_0);// UIColor, default nil: same as foreground color

UIKIT_EXTERNNSAttributedStringKeyconstNSStrikethroughColorAttributeNameNS_AVAILABLE(10_0,7_0);// UIColor, default nil: same as foreground color

UIKIT_EXTERNNSAttributedStringKeyconstNSObliquenessAttributeNameNS_AVAILABLE(10_0,7_0);// NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew

UIKIT_EXTERNNSAttributedStringKeyconstNSExpansionAttributeNameNS_AVAILABLE(10_0,7_0);// NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion

UIKIT_EXTERNNSAttributedStringKeyconstNSWritingDirectionAttributeNameNS_AVAILABLE(10_6,7_0);// NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters.? The control characters can be obtained by masking NSWritingDirection and NSWritingDirectionFormatType values.? LRE: NSWritingDirectionLeftToRight|NSWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSWritingDirectionOverride,

UIKIT_EXTERNNSAttributedStringKeyconstNSVerticalGlyphFormAttributeNameNS_AVAILABLE(10_7,6_0);// An NSNumber containing an integer value.? 0 means horizontal text.? 1 indicates vertical text.? If not specified, it could follow higher-level vertical orientation settings.? Currently on iOS, it's always horizontal.? The behavior for any other value is undefined.

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末荚坞,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌飞蚓,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件党饮,死亡現(xiàn)場離奇詭異述雾,居然都是意外死亡,警方通過查閱死者的電腦和手機烤低,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進店門肘交,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人扑馁,你說我怎么就攤上這事涯呻。” “怎么了腻要?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵复罐,是天一觀的道長。 經常有香客問我雄家,道長效诅,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任趟济,我火速辦了婚禮乱投,結果婚禮上,老公的妹妹穿的比我還像新娘顷编。我一直安慰自己戚炫,他們只是感情好,可當我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布媳纬。 她就那樣靜靜地躺著嘹悼,像睡著了一般。 火紅的嫁衣襯著肌膚如雪层宫。 梳的紋絲不亂的頭發(fā)上杨伙,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天,我揣著相機與錄音萌腿,去河邊找鬼限匣。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的米死。 我是一名探鬼主播锌历,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼峦筒!你這毒婦竟也來了究西?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤物喷,失蹤者是張志新(化名)和其女友劉穎卤材,沒想到半個月后,有當地人在樹林里發(fā)現(xiàn)了一具尸體峦失,經...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡扇丛,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了尉辑。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片帆精。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖隧魄,靈堂內的尸體忽然破棺而出卓练,到底是詐尸還是另有隱情,我是刑警寧澤购啄,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布昆庇,位于F島的核電站,受9級特大地震影響闸溃,放射性物質發(fā)生泄漏整吆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一辉川、第九天 我趴在偏房一處隱蔽的房頂上張望表蝙。 院中可真熱鬧,春花似錦乓旗、人聲如沸府蛇。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽汇跨。三九已至,卻和暖如春妆距,著一層夾襖步出監(jiān)牢的瞬間穷遂,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工娱据, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留蚪黑,地道東北人。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像忌穿,于是被迫代替她去往敵國和親抒寂。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內容