美文网首页
IOS开发-设置UIButton 图片在左 文字在右

IOS开发-设置UIButton 图片在左 文字在右

作者: swluan | 来源:发表于2017-01-06 15:17 被阅读0次
   UIButton *movableButton = [[UIButton alloc] init];
    movableButton.frame = CGRectMake(SCREEN_WIDTH-100, 160, 90, 30);
    [movableButton addTarget:self action:@selector(goPlist) forControlEvents:UIControlEventTouchUpInside];
    [movableButton setBackgroundColor:[UIColor colorWithHexString:@"#C00023"]];
    [movableButton setImage:[UIImage imageNamed:@"icon_screen"] forState:UIControlStateNormal];
    [movableButton setTitle:@"FILTER" forState:UIControlStateNormal];
    [movableButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [movableButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    movableButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    //设置button图片的偏移量,距(top, left, bottom, right)的像素点为(5, 10, 5, 60)
    movableButton.imageEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 60);
    //设置button标题的偏移量,这个偏移量是相对于图片的
    movableButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.view addSubview:movableButton];

相关文章

网友评论

      本文标题:IOS开发-设置UIButton 图片在左 文字在右

      本文链接:https://www.haomeiwen.com/subject/wsxxbttx.html