UIButton应用细节

2015-08-27  本文已影响75人  撸码是一种情怀
- (void)setHighlighted:(BOOL)highlighted{};
// 此举例实现的功能是让button内部的imageView和label上下排布
- (void)layoutSubviews
{
  [super layoutSubviews];
  CGFloat titleH =21; CGFloat imageX =0;
  CGFloat imageY =0;
  CGFloatimageW = self.bounds.size.width;
  CGFloat imageH =self.bounds.size.height-titleH;
  self.imageView.frame = CGRectMake(imageX,imageY, imageW, imageH);
  self.titleLabel.frame = CGRectMake(imageX,imageH, imageW, titleH);
}
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.imageView.contentMode= UIViewContentModeCenter;
button.titleLabel.numberOfLines = 0;
[btn sizeToFit];
// 自定义button---MainTagSubIcon(测试图片名称)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"MainTagSubIcon"] forState:UIControlStateNormal];
// 设置button的尺寸
[button sizeToFit];
// 设置内边距对应的位置为负数
button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

上一篇 下一篇

猜你喜欢

热点阅读