XJTopMenu.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // XJTopMenu.m
  3. // XJAVPlayer
  4. //
  5. // Created by xj_love on 2016/10/27.
  6. // Copyright © 2016年 Xander. All rights reserved.
  7. //
  8. #import "XJTopMenu.h"
  9. #import "UIView+SCYCategory.h"
  10. @interface XJTopMenu ()
  11. @property (nonatomic, strong)UIButton *backButton;
  12. @property (nonatomic, strong)UILabel *titleLabel;
  13. @end
  14. @implementation XJTopMenu
  15. - (instancetype)initWithFrame:(CGRect)frame{
  16. if (self = [super initWithFrame:frame]) {
  17. [self addAllView];
  18. }
  19. return self;
  20. }
  21. - (void)addAllView{
  22. [self addSubview:self.backButton];
  23. [self addSubview:self.titleLabel];
  24. }
  25. #pragma mark - **************************** 控件事件 *************************************
  26. - (void)goBack{
  27. if (self.xjTopGoBack) {
  28. self.xjTopGoBack();
  29. }
  30. }
  31. #pragma mark - **************************** 懒加载 *************************************
  32. - (UIButton *)backButton{
  33. if (_backButton == nil) {
  34. _backButton = [[UIButton alloc] init];
  35. [_backButton setBackgroundImage:[UIImage imageNamed:@"go_back"] forState:UIControlStateNormal];
  36. [_backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  37. }
  38. return _backButton;
  39. }
  40. - (UILabel *)titleLabel{
  41. if (_titleLabel == nil) {
  42. _titleLabel = [[UILabel alloc] init];
  43. _titleLabel.font = [UIFont systemFontOfSize:18];
  44. _titleLabel.textColor = [UIColor whiteColor];
  45. }
  46. return _titleLabel;
  47. }
  48. - (void)setXjAvTitle:(NSString *)xjAvTitle{
  49. _xjAvTitle = xjAvTitle;
  50. _titleLabel.text = _xjAvTitle;
  51. }
  52. #pragma mark - **************************** 布局 *************************************
  53. - (void)layoutSubviews{
  54. [super layoutSubviews];
  55. if (self.xjHidenBackBtn) {
  56. self.backButton = nil;
  57. }else{
  58. self.backButton.frame = CGRectMake(5, 8, 24, 24);
  59. }
  60. if (self.xjHidenBackBtn) {
  61. self.titleLabel.frame = CGRectMake(5, 5 , 200, 30);
  62. }else{
  63. self.titleLabel.frame = CGRectMake(45, 5 , 200, 30);
  64. }
  65. }
  66. @end