效果图
项目结构
匿名类目 vs IBOutlet
只有在.m文件中建立了匿名类目,才能连接storyBoard中的IBOutlet
view.m
@interface WheelView ()
@property (weak, nonatomic) IBOutlet UIImageView *centerView;
@end
加载xib文件
+ (instancetype)wheelView{
return [[[NSBundle mainBundle] loadNibNamed:@"WheelView" owner:nil options:nil] lastObject];
}
裁剪图片
UIImage *img = [UIImage imageNamed:@"LuckyAstrology"];
CGFloat smallW = img.size.width / 12 * [UIScreen mainScreen].scale;
CGFloat smallH = img.size.height * [UIScreen mainScreen].scale;
CGRect smallRect = CGRectMake(index * smallW, 0, smallW, smallH);
CGImageRef smallImage = CGImageCreateWithImageInRect(img.CGImage, smallRect);
[btn setImage:[UIImage imageWithCGImage:smallImage] forState:UIControlStateNormal];