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];

  • 相关阅读:
    Robot Framework + Selenium library + IEDriver环境搭建
    【转】大话测试数据(一)
    TEST DESIGN TECHNIQUES: AN OVERVIEW
    24 WHEN CAN WE STOP TESTING?
    MySql Trace
    ORGANISING THE TEST CASES
    angular教程
    vue报错一
    sort()
    时间戳
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5198800.html
Copyright © 2011-2022 走看看