objective-c - 创建 UIImageView

标签 objective-c ios cocoa-touch uiimageview

如何在代码中创建 UIImageView,而不是在我的 xib 文件中创建它?

最佳答案

您可以单独创建一个 UIImage,并从您的 UIImage 创建您的 UIImageView。

UIImage *myImage = [UIImage imageNamed:@"great_pic.png"];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];

然后,设置 UIImageView 的大小

[myImageView setFrame:CGRectMake(0, 0, 100, 200)];

用你的图像做任何你想做的事,但不要忘记释放它。

[anotherView addSubview:myImageView];
[myImageView release];

关于objective-c - 创建 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7891613/

相关文章:

ios - Storyboard中带有 UIButtons 的 PaintCode 2

ios - 为我的变量编写自定义 Setter - Swift

objective-c - 如何自动激活 OS X 服务菜单中的项目

ios - 如何避免 firestore 中的重复文件?

cocoa-touch - UISegmentedControl 不随 super View 缩放

iphone - 以编程方式在 Objective-C 中创建属性?

objective-c - NSMutableString 和(字符)编码问题 : getting\U00fc in case of ü

ios - 自定义 MPMoviePlayerController 中的 UI slider ?

iphone - 如何在本地保存 SKProduct 对象?

iphone - CGContextSetShadow 不产生任何结果