IOS代碼布局(六) UILabel

來源:互聯網
上載者:User

標籤:範圍   代碼   建立   ring   contents   origin   round   str   bsp   

(一)初始化

  1、建立

UILabel *lblBid=[[UILabel alloc] initWithFrame:CGRectMake(90,5,rect.size.width-110,30)];

  2、設定背景顏色

    lblBid.backgroundColor=[UIColor clearColor];

  3、設定標籤內容

    lblBid.text=_txtBid;

  4、設定行數

lblPs.numberOfLines=0;

  5、調適型配置(需要和4一起使用)

[lblPs sizeToFit];

  6、加入視圖

[self.view addSubview:lblPs];

 

(二)設定單列標籤並可上下滑動(ScrollView + Label)

  思路:其實就是設定scroll為單行,然後自適應label,再在set方法中將scrollview的實際大小設定為label的大小

UIScrollView *scrollViewPs = [[UIScrollView alloc] init];    scrollViewPs.frame = CGRectMake(lblAV.frame.origin.x, lblAV.frame.origin.y+lblAV.frame.size.height, lblBid.frame.size.width, lblBid.frame.size.height); // frame中的size指UIScrollView的可視範圍    scrollViewPs.backgroundColor = [UIColor clearColor];    scrollViewPs.showsVerticalScrollIndicator = YES;    scrollViewPs.scrollEnabled=YES;    [bgClearView1 addSubview:scrollViewPs];        UILabel *lblPs=[[UILabel alloc] initWithFrame:CGRectMake(0,0,scrollViewPs.frame.size.width,100)];    lblPs.text=_txtPs;    lblPs.numberOfLines=0;              //調適型配置 步驟1    [lblPs sizeToFit];                  //調適型配置 步驟2    [scrollViewPs addSubview:lblPs];

在txtPs的set方法中設定scrollview的大小與label一樣

-(void)setTxtPs:(NSString *)txtPs{    scrollViewPs.contentSize = lblPs.frame.size;    _txtPs=txtPs;}

 

IOS代碼布局(六) UILabel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.