第一种,先创建然后设置 image
,但是创建后需要设置 frame
UIImageView *searchIcon = [[UIImageView alloc] init];
searchIcon.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
searchIcon.width = 30;
searchIcon.height = 30;
第二种,由一个 UIImage
对象创建,这时 frame
就是图片对象的frame
,不需要再额外设置
UIImage *image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
UIImageView *searchIcon = [[UIImageView alloc] initWithImage:image];