// // SIcon_button.m // LN_School // // Created by apple on 2017/4/7. // Copyright © 2017年 Danson. All rights reserved. // #import "SIcon_button.h" @implementation SIcon_button -(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor whiteColor]; self.titleLabel.textAlignment = NSTextAlignmentCenter; self.imageView.contentMode = UIViewContentModeScaleAspectFill; self.imageView.layer.masksToBounds = YES; CGFloat wid = frame.size.width; _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, wid / 5.0, wid, wid * 4 / 10.0)]; _contentLabel.backgroundColor = [UIColor clearColor]; [_contentLabel setTextAlignment:NSTextAlignmentCenter]; [self addSubview:_contentLabel]; } return self; } -(CGRect)imageRectForContentRect:(CGRect)contentRect { CGFloat wid = self.frame.size.width; return CGRectMake(wid * 3 / 10.0, wid / 5.0, wid * 4 / 10.0, wid * 4 / 10.0); } -(CGRect)titleRectForContentRect:(CGRect)contentRect { CGFloat wid = self.frame.size.width; return CGRectMake(0, wid * 6 / 10.0, wid, wid * 3 / 10.0); } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end