精通ios開發第六版,第一章,文章中的例子及習題.

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   ar   使用   for   sp   

第一章

 1 #import "ViewController.h" 2  3 @interface ViewController () 4  5 @end 6  7 @implementation ViewController 8  9 10 - (IBAction)buttonPressed:(UIButton *)sender {11     //取出按鈕的title12     NSString *title = [sender titleForState:UIControlStateNormal];13     14     //用取出的title格式化為字串,並賦值給新的NSString對象15     NSString *plainText = [NSString stringWithFormat:@"pressing %@ button",title];16     17 //    _statusLabel.text = plainText;    //將格式化的字串賦給標籤的text屬性18     19     //可變的字串屬性類,建立對象20     NSMutableAttributedString *textStyle = [[NSMutableAttributedString alloc]initWithString:plainText];21     22     //NSDictionary字典新文法 @{}用於儲存字串屬性..  NSArray 數組新文法是 @[]23     NSDictionary *dict =24     @{25       NSFontAttributeName:[UIFont boldSystemFontOfSize:_statusLabel.font.pointSize]26       };27     28     //取出plainText字串中待改變的子字串  即 title  也可以使用@""取出其他字串29     NSRange nameRange = [plainText rangeOfString:title];30     31     //設定字串屬性. 32     [textStyle setAttributes:dict range:nameRange];33     34     _statusLabel.attributedText = textStyle;35     36     37 }38 @end

 

精通ios開發第六版,第一章,文章中的例子及習題.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.