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

   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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容