美文网首页
Button 左图片右文字

Button 左图片右文字

作者: andrewliu20 | 来源:发表于2018-08-20 17:54 被阅读6次
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 100, 50);
    button.backgroundColor = [UIColor clearColor];
    //设置button正常状态下的图片
    [button setImage:[UIImage imageNamed:@"图片.png"] forState:UIControlStateNormal];
    //设置button高亮状态下的图片
    [button setImage:[UIImage imageNamed:@"图片.png"] forState:UIControlStateHighlighted];
    //设置button正常状态下的背景图
    [button setBackgroundImage:[UIImage imageNamed:@"背景图片.png"] forState:UIControlStateNormal];
    //设置button高亮状态下的背景图
    [button setBackgroundImage:[UIImage imageNamed:@"背景图片.png"] forState:UIControlStateHighlighted];
    //button图片的偏移量,距上左下右分别(10, 10, 10, 60)像素点
    button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 60);
    [button setTitle:@"文字" forState:UIControlStateNormal];
    //button标题的偏移量,这个偏移量是相对于图片的
    button.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    //设置button正常状态下的标题颜色
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    //设置button高亮状态下的标题颜色
    [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    

    相关文章

      网友评论

          本文标题:Button 左图片右文字

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