zoukankan      html  css  js  c++  java
  • 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];


  • 相关阅读:
    正则表达式复习 (?<=) (?=)
    HTML 30分钟入门教程
    C# 多线程详解
    C# List
    C# 枚举
    C# 线程数
    C# 泛型2
    C# 泛型
    C# 结构体
    不用Google Adsense的84个赚钱方法
  • 原文地址:https://www.cnblogs.com/llguanli/p/6961582.html
Copyright © 2011-2022 走看看