BViewController.m 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // BViewController.m
  3. // MainProject
  4. //
  5. // Created by casa on 2016/12/10.
  6. // Copyright © 2016年 casa. All rights reserved.
  7. //
  8. #import "BViewController.h"
  9. @interface BViewController ()
  10. @property (nonatomic, strong) UILabel *contentLabel;
  11. @end
  12. @implementation BViewController
  13. #pragma mark - life cycle
  14. - (instancetype)initWithContentText:(NSString *)contentText
  15. {
  16. self = [super init];
  17. if (self) {
  18. self.contentLabel.text = contentText;
  19. }
  20. return self;
  21. }
  22. - (void)viewDidLoad
  23. {
  24. [super viewDidLoad];
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. [self.view addSubview:self.contentLabel];
  27. }
  28. - (void)viewWillLayoutSubviews
  29. {
  30. [super viewWillLayoutSubviews];
  31. [self.contentLabel sizeToFit];
  32. self.contentLabel.frame = CGRectMake(0, 0, 300, 100);
  33. self.contentLabel.center = self.view.center;
  34. }
  35. #pragma mark - getters and setters
  36. - (UILabel *)contentLabel
  37. {
  38. if (_contentLabel == nil) {
  39. _contentLabel = [[UILabel alloc] init];
  40. _contentLabel.textColor = [UIColor blueColor];
  41. }
  42. return _contentLabel;
  43. }
  44. @end