zoukankan      html  css  js  c++  java
  • button setimage 设置

        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kScreenWidth, 44)];

        headView.backgroundColor = [UIColor clearColor];

        [self.view addSubview:headView];

        

        

        UIButton *leftButon = [UIButton buttonWithType:UIButtonTypeCustom];

        [leftButon setTitle:@"登录OTATO" forState:UIControlStateNormal];

        leftButon.frame = CGRectMake(0, 0, kScreenWidth / 2, 44);

        leftButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;

        leftButon.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);

     

    /*

    这里使用

    button.titleLabel.textAlignment = NSTextAlignmentLeft; 这行代码是没有效果的,这只是让标签中的文本左对齐,但

    并没有改变标签在按钮中的对齐方式。

     

    所以,我们首先要使用

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 这行代码,把按钮的内容(控件)

    的对齐方式修改为水平左对齐,但是这们会紧紧靠着左边,不好看,

    所以我们还可以修改属性:

     

    button.titleEdgeInsets = UIEdgeInsetsMake(01000);

    这行代码可以让按钮的内容(控件)距离左边10个像素,这样就好看多了

    */

        [leftButon setImage:[UIImage imageNamed:@"arrow_left_white"] forState:UIControlStateNormal];

        leftButon.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 100);

        [headView addSubview:leftButon];

        

        UIButton *rightButon = [UIButton buttonWithType:UIButtonTypeCustom];

        [rightButon setTitle:@"/ 手机注册" forState:UIControlStateNormal];

        rightButon.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 44);

        rightButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

        [headView addSubview:rightButon];

        

        [leftButon addTarget:self action:@selector(goToSingUpVC) forControlEvents:UIControlEventTouchUpInside];

  • 相关阅读:
    vscode 前端好用插件汇总
    IE8和IE9下textarea滚动选中的问题
    javascript实现数字整数位每三位一个逗号分隔
    简单枚举(算法竞赛入门经典)
    拓扑排序(算法竞赛入门经典)
    七桥问题--欧拉(算法竞赛入门经典)
    走迷宫问题 算法竞赛入门经典
    ZOJ1008
    ZOJ1163
    HDU 1069 Monkey and Banana
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5198800.html
Copyright © 2011-2022 走看看