Latest 0.0.1
Homepage https://github.com/lvsf/UIButton-HHAddLayout
License MIT
Platforms ios 7.0, requires ARC
Authors

UIButton-HHAddLayout

  • 使用UIButton扩展方便地调整按钮原本图片和文本的位置

    How to use

  • code
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:20]];
    [btn setTitle:@"任飘渺" forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"任飘渺"] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor orangeColor]];
    [btn setHh_layoutStyle:HHButtonLayoutStyleImageOnTheTop];
    [btn sizeToFit];
    [btn setFrame:(CGRect){CGPointMake(10, 75),btn.bounds.size}];
    [self.view addSubview:btn];

UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1.titleLabel setNumberOfLines:0];
[btn1 setTitle:@"秋水浮萍任飘渺" forState:UIControlStateNormal];
[btn1 setImage:[UIImage imageNamed:@"任飘渺"] forState:UIControlStateNormal];
[btn1 setBackgroundColor:[UIColor lightGrayColor]];
[btn1 setContentEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[btn1 setHh_layoutStyle:HHButtonLayoutStyleImageOnTheBottom];
[btn1 setHh_preferredMaxImageSize:CGSizeMake(35, 35)];
[btn1 setHh_verticalSpacing:10];
[btn1 setHh_preferredMaxLayoutWidth:105];
[btn1 sizeToFit];
[btn1 setFrame:(CGRect){CGPointMake(CGRectGetMaxX(btn.frame) + 5, 75),btn1.bounds.size}];
[self.view addSubview:btn1];

UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn2.titleLabel setNumberOfLines:0];
[btn2.titleLabel setFont:[UIFont systemFontOfSize:12]];
[btn2 setTitle:@"秋水浮萍任飘渺" forState:UIControlStateNormal];
[btn2 setImage:[UIImage imageNamed:@"任飘渺"] forState:UIControlStateNormal];
[btn2 setBackgroundColor:[UIColor lightGrayColor]];
[btn2 setContentEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[btn2 setHh_layoutStyle:HHButtonLayoutStyleImageOnTheLeft];
[btn2 setHh_verticalSpacing:10];
[btn2 setHh_preferredMaxImageSize:CGSizeMake(35, 35)];
[btn2 setHh_preferredMaxLayoutWidth:100];
[btn2 setHh_horizontalSpacing:10];
[btn2 setFrame:CGRectMake(CGRectGetMinX(btn1.frame), CGRectGetMaxY(btn1.frame) + 5, CGRectGetWidth(btn1.frame), CGRectGetHeight(btn.frame) – CGRectGetHeight(btn1.frame) – 5)];
[self.view addSubview:btn2];

* xib
``` objective-c
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.xibButton setHh_layoutStyle:HHButtonLayoutStyleImageOnTheRight];
    [self.xibButton setHh_preferredMaxImageSize:CGSizeMake(80, 80)];
}
  • UIBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:({
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [btn setTitle:@"任飘渺" forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"任飘渺"] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor orangeColor]];
    [btn setHh_layoutStyle:HHButtonLayoutStyleImageOnTheRight];
    [btn setHh_preferredMaxImageSize:CGSizeMake(25, 25)];
    [btn sizeToFit];
    btn;
    })];
  • 运行结果
    ScreenShot BarButtonItem

Latest podspec

{
    "name": "UIButton+HHAddLayout",
    "version": "0.0.1",
    "summary": "u4f7fu7528UIButtonu6269u5c55u65b9u4fbfu5730u8c03u6574u6309u94aeu539fu672cu56feu7247u548cu6587u672cu7684u4f4du7f6e",
    "homepage": "https://github.com/lvsf/UIButton-HHAddLayout",
    "license": "MIT",
    "authors": {
        "lvsf": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/lvsf/UIButton-HHAddLayout.git",
        "tag": "0.0.1"
    },
    "source_files": "UIButton-HHAddLayout/Class/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This