總結(jié)2017.6.23

關(guān)于Button

//設(shè)置圓角和顏色

業(yè)界對(duì)于圓角優(yōu)化很多方式,大家可以搜一下相關(guān)文章。本文只針對(duì)UILabel的cornerRadius方式進(jìn)行講解。
先說(shuō)一下cornerRadius屬性,它是影響layer顯示的backgroundColor和border,對(duì)layer的contents不起作用。
對(duì)于不需要設(shè)置label的backgroundColor,只設(shè)置borderWidth、borderColor的label,直接設(shè)置cornerRadius,不需要設(shè)置masksToBounds = YES,就可以實(shí)現(xiàn)圓角功能。
對(duì)于需要同時(shí)設(shè)置label的backgroundColor時(shí),直接設(shè)置cornerRadius是不能正常顯示圓角的,
原因是:UILabel設(shè)置backgroundColor的行為,不再是設(shè)定layer的背景色而是為contents設(shè)置背景色。所以解決方式是我們不去設(shè)置label的backgroundColor,而是直接設(shè)置label.layer.backgroundColor,這樣就可以實(shí)現(xiàn)單獨(dú)設(shè)置cornerRadius,顯示圓角的效果。
UILabel *tagLabel = [UILabel new];tagLabel.text = @"減";
tagLabel.textColor = [UIColor whiteColor];
tagLabel.font = [UIFont systemFontOfSize:12];
tagLabel.layer.backgroundColor = [UIColor greenColor].CGColor;
tagLabel.layer.cornerRadius = 2;


文字大小自適應(yīng)



1、確定Label或Button的字體大小,使其寬度自適應(yīng)

UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
contentLabel.font = [UIFont systemFontOfSize:15];//-------->定義Font的大小
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.text = @"我已知曉,且已閱讀并同意以上條款";
[contentLabel sizeToFit];//-------->注意和上面一句代碼順序不能顛倒
[self.View addSubview:contentLabel];

2、確定Label或Button的寬度,使字體大小自適應(yīng)

//無(wú)需自己設(shè)置字體大小
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.text = @"我已知曉,且已閱讀并同意以上條款";
contentLabel.adjustsFontSizeToFitWidth = YES;//默認(rèn)為NO-------->注意和上面一句代碼順序不能顛倒
[self.View addSubview:contentLabel];

如果是Button的話(huà),和上面一樣,只有一點(diǎn)小小的區(qū)別:

[button.titleLabel sizeToFit];
button.titleLabel.adjustsFontSizeToFitWidth = YES;


常用的宏

#define KSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define KSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

顏色的宏(隨機(jī)色和自定義顏色)


// 1.獲得RGB顏色
#define JMColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

//2.隨機(jī)色
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]


關(guān)于cell和tableView

//選中時(shí)沒(méi)有顏色效果
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,433評(píng)論 4 61
  • 1. 和他認(rèn)識(shí)到真正見(jiàn)面差不多隔了3個(gè)多月,我們?cè)谝粋€(gè)校內(nèi)的單身群里認(rèn)識(shí),8月他加了我微信后也是有聊沒(méi)聊的聯(lián)系...
    aae8a8604d51閱讀 320評(píng)論 0 0
  • 有一種情懷,割舍不掉 有一絲惦念,魂?duì)繅?mèng)縈 有一份記憶,如初之美 生活里我們經(jīng)歷了大大小小的絕望,也嘗過(guò)甜甜的希望...
    靜姝JingShu閱讀 366評(píng)論 0 2
  • #參與#——紙上得來(lái)終覺(jué)淺,絕知此事要躬行 參與的重要性不言而喻。 自我提升、發(fā)展更有效的途徑是參與。 參與就像是...
    zzzzzzzzzzzzzzc閱讀 230評(píng)論 0 0
  • 一、衛(wèi)哲 1.嘉御基金合伙創(chuàng)始人兼董事長(zhǎng)2.前阿里巴巴集團(tuán)執(zhí)行副總裁、兼阿里巴巴企業(yè)(B2B)電子商務(wù)總裁3.32...
    胡賢彬閱讀 5,344評(píng)論 1 16

友情鏈接更多精彩內(nèi)容