IOS總結_實現UIButton的圖文混排(二)

    很久沒有寫博客了,之前寫過一篇關於UIButton圖文混排的,但是有點複雜,今天來一個比較簡單地,相信大家回用得着


    UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(60, 90, 100, 40)];

    //加文字

    [button setTitle:@"描述文字" forState:UIControlStateNormal];

    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    //加圖片

    [button setImage:[UIImage imageNamed:@"pulldown"] forState:UIControlStateNormal];

    //加邊框

    button.layer.borderColor=[UIColor redColor].CGColor;

    button.layer.borderWidth=0.5;


   這就是不改變位置的情況下混排的效果,根據大家不同的需要大家肯定會改變其位置

    

    

    //改變圖文位置 左右並排

    button.titleEdgeInsets=UIEdgeInsetsMake(0, -button.imageView.frame.size.width, 0, button.imageView.frame.size.width);

    button.imageEdgeInsets=UIEdgeInsetsMake(0, button.titleLabel.frame.size.width+5, 0, 0);

    


說明:EdgeInsets的位置是相對改變的,具體大家可以更具代碼去理解


    [self.view addSubview:button];


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章