我可以在自定义 UIAlertView 中添加 UIImageView 吗?
我已经有一个自定义 UIAlertView,我想在其中添加 UIImageView 以添加自定义 UIAlertView。
我已经添加了带有数组的 UIImageView 并开始对其进行动画处理,但它不起作用。如果你愿意,我可以发布代码。
请尽快帮助我。我被卡住了:(
这是代码
- (id)initWithImage:(UIImage *)image text:(NSString *)text
{
//CGSize imageSize = self.backgroundImage.size;
CGRect frame = [[UIScreen mainScreen] bounds];
width = frame.size.width;
height = frame.size.height;
if (self = [super init])
{
loadtext = [[UILabel alloc]initWithFrame:CGRectZero];
loadtext.textColor = [UIColor blackColor];
loadtext.backgroundColor = [UIColor whiteColor];
[self addSubview:loadtext];
//Create the first status image and the indicator view
UIImage *statusImage = [UIImage imageNamed:@"status1.png"];
activityImageView = [[UIImageView alloc]
initWithImage:statusImage];
//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"status1.png"],
[UIImage imageNamed:@"status2.png"],
[UIImage imageNamed:@"status3.png"],
[UIImage imageNamed:@"status4.png"],
[UIImage imageNamed:@"status5.png"],
[UIImage imageNamed:@"status6.png"],
[UIImage imageNamed:@"status7.png"],
nil];
//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 1.0;
//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectZero;
//Start the animation
[activityImageView startAnimating];
//Add your custom activity indicator to your current view
[self addSubview:activityImageView];
//self.backgroundImage = image;
}
return self;
}
- (void) layoutSubviews{
//lblUserName.transform = CGAffineTransformMake;
//[lblUserName sizeToFit];
CGRect textRect = activityImageView.frame;
textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect))/2;
textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect))/2;
textRect.origin.x -= 100.0;
textRect.origin.y -= 60.0;
textRect.size.height = 30;
textRect.size.width = self.bounds.size.width - 50;
activityImageView.frame = textRect;
}
这段代码开始工作。但是现在这个 UIImageView 占据了我的整个屏幕并出现在 UIAlertView 前面。虽然我给出了 10px 高度和宽度。它显示相同。有人可以帮忙吗?
谢谢, 安克斯
I already have a custom UIAlertView and in which i want to add UIImageView for adding custom UIAlertView.
I have already added UIImageView with array and start animating it but it doesn't work. If you want, I can post the code.
Please help me ASAP. I'm stuck :(
Here is code
- (id)initWithImage:(UIImage *)image text:(NSString *)text
{
//CGSize imageSize = self.backgroundImage.size;
CGRect frame = [[UIScreen mainScreen] bounds];
width = frame.size.width;
height = frame.size.height;
if (self = [super init])
{
loadtext = [[UILabel alloc]initWithFrame:CGRectZero];
loadtext.textColor = [UIColor blackColor];
loadtext.backgroundColor = [UIColor whiteColor];
[self addSubview:loadtext];
//Create the first status image and the indicator view
UIImage *statusImage = [UIImage imageNamed:@"status1.png"];
activityImageView = [[UIImageView alloc]
initWithImage:statusImage];
//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"status1.png"],
[UIImage imageNamed:@"status2.png"],
[UIImage imageNamed:@"status3.png"],
[UIImage imageNamed:@"status4.png"],
[UIImage imageNamed:@"status5.png"],
[UIImage imageNamed:@"status6.png"],
[UIImage imageNamed:@"status7.png"],
nil];
//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 1.0;
//Position the activity image view somewhere in
//the middle of your current view
activityImageView.frame = CGRectZero;
//Start the animation
[activityImageView startAnimating];
//Add your custom activity indicator to your current view
[self addSubview:activityImageView];
//self.backgroundImage = image;
}
return self;
}
- (void) layoutSubviews{
//lblUserName.transform = CGAffineTransformMake;
//[lblUserName sizeToFit];
CGRect textRect = activityImageView.frame;
textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect))/2;
textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect))/2;
textRect.origin.x -= 100.0;
textRect.origin.y -= 60.0;
textRect.size.height = 30;
textRect.size.width = self.bounds.size.width - 50;
activityImageView.frame = textRect;
}
This code started working. But now this UIImageView is taking my whole screen and coming in front of UIAlertView. Though i give 10px height and width. It shows same. Can anyone help please?
Thanks,
Anks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以在自定义警报视图中添加图像视图。不需要采用 UIView 自定义类,而是需要采用 UIImage-View &您可以使用图像视图属性。
Yes, you can add image view - in custom alert-view. instead of taking as UIView custom class, need to take UIImage-View & you can use image-view properties.
将
activityImageView.frame = CGRectZero;
更改为某个自定义框架。
例如:
Change
activityImageView.frame = CGRectZero;
to some custom frame.
eg: