TYTabTitleViewCell.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #import "TYTabTitleViewCell.h"
  2. @interface TYTabTitleViewCell ()
  3. @property (nonatomic, weak) UILabel *titleLabel;
  4. @end
  5. @implementation TYTabTitleViewCell
  6. - (instancetype)initWithFrame:(CGRect)frame
  7. {
  8. if (self = [super initWithFrame:frame]) {
  9. [self addTabTitleLabel];
  10. }
  11. return self;
  12. }
  13. - (instancetype)initWithCoder:(NSCoder *)aDecoder
  14. {
  15. if (self = [super initWithCoder:aDecoder]) {
  16. [self addTabTitleLabel];
  17. }
  18. return self;
  19. }
  20. - (void)addTabTitleLabel
  21. {
  22. UILabel *titleLabel = [[UILabel alloc]init];
  23. titleLabel.font = [UIFont fontWithName:@"Microsoft YaHei" size:14];
  24. titleLabel.textColor = [UIColor darkTextColor];
  25. titleLabel.textAlignment = NSTextAlignmentCenter;
  26. [self.contentView addSubview:titleLabel];
  27. titleLabel.layer.masksToBounds = YES;
  28. titleLabel.layer.cornerRadius = 15;
  29. _titleLabel = titleLabel;
  30. }
  31. - (void)layoutSubviews
  32. {
  33. //tabbar title位置
  34. [super layoutSubviews];
  35. int x = self.contentView.bounds.origin.x;
  36. int y = self.contentView.bounds.origin.y;
  37. int width = self.contentView.bounds.size.width;
  38. int height = self.contentView.bounds.size.height;
  39. _titleLabel.frame = CGRectMake(x, y+5, width, height);
  40. }
  41. @end