Nav apraksta

FLImageTextButton.m 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // FLImageTextButton.m
  3. // FirstLink
  4. //
  5. // Created by Lemon on 15/5/8.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FLImageTextButton.h"
  9. @implementation FLImageTextButton
  10. - (id)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. self.userInteractionEnabled = YES;
  14. [self layoutAllCompoments];
  15. }
  16. return self;
  17. }
  18. #pragma mark - Properties
  19. - (UIImageView *)imageView {
  20. if (!_imageView) {
  21. _imageView = [[UIImageView alloc] init];
  22. }
  23. return _imageView;
  24. }
  25. - (UILabel *)textLabel {
  26. if (!_textLabel) {
  27. _textLabel = [[UILabel alloc] init];
  28. _textLabel.textColor = UIColorFromRGB(0xbbbbbb);
  29. _textLabel.font = [UIFont systemFontOfSize:14];
  30. _textLabel.textAlignment = NSTextAlignmentCenter;
  31. _textLabel.numberOfLines = 0;
  32. }
  33. return _textLabel;
  34. }
  35. #pragma mark - Layout
  36. - (void)layoutAllCompoments {
  37. [self addSubview:self.imageView];
  38. self.imageView.translatesAutoresizingMaskIntoConstraints = NO;
  39. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[_imageView]-0-|"
  40. options:0
  41. metrics:nil
  42. views:NSDictionaryOfVariableBindings(_imageView)]];
  43. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_imageView]"
  44. options:0
  45. metrics:nil
  46. views:NSDictionaryOfVariableBindings(_imageView)]];
  47. [self addSubview:self.textLabel];
  48. self.textLabel.translatesAutoresizingMaskIntoConstraints = NO;
  49. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[_textLabel]-0-|"
  50. options:0
  51. metrics:nil
  52. views:NSDictionaryOfVariableBindings(_textLabel)]];
  53. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_imageView]-10-[_textLabel(16)]"
  54. options:0
  55. metrics:nil
  56. views:NSDictionaryOfVariableBindings(_imageView, _textLabel)]];
  57. }
  58. @end