123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // FLImageTextButton.m
- // FirstLink
- //
- // Created by Lemon on 15/5/8.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FLImageTextButton.h"
- @implementation FLImageTextButton
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.userInteractionEnabled = YES;
- [self layoutAllCompoments];
- }
- return self;
- }
- #pragma mark - Properties
- - (UIImageView *)imageView {
- if (!_imageView) {
- _imageView = [[UIImageView alloc] init];
- }
- return _imageView;
- }
- - (UILabel *)textLabel {
- if (!_textLabel) {
- _textLabel = [[UILabel alloc] init];
- _textLabel.textColor = UIColorFromRGB(0xbbbbbb);
- _textLabel.font = [UIFont systemFontOfSize:14];
- _textLabel.textAlignment = NSTextAlignmentCenter;
- _textLabel.numberOfLines = 0;
- }
- return _textLabel;
- }
- #pragma mark - Layout
- - (void)layoutAllCompoments {
- [self addSubview:self.imageView];
- self.imageView.translatesAutoresizingMaskIntoConstraints = NO;
- [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[_imageView]-0-|"
- options:0
- metrics:nil
- views:NSDictionaryOfVariableBindings(_imageView)]];
- [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_imageView]"
- options:0
- metrics:nil
- views:NSDictionaryOfVariableBindings(_imageView)]];
-
- [self addSubview:self.textLabel];
- self.textLabel.translatesAutoresizingMaskIntoConstraints = NO;
- [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[_textLabel]-0-|"
- options:0
- metrics:nil
- views:NSDictionaryOfVariableBindings(_textLabel)]];
- [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_imageView]-10-[_textLabel(16)]"
- options:0
- metrics:nil
- views:NSDictionaryOfVariableBindings(_imageView, _textLabel)]];
- }
- @end
|