我可以在自定义 UIAlertView 中添加 UIImageView 吗?

发布于 2024-11-08 21:48:51 字数 2876 浏览 0 评论 0原文

我已经有一个自定义 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送你一个梦 2024-11-15 21:48:51

是的,您可以在自定义警报视图中添加图像视图。不需要采用 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.

杀お生予夺 2024-11-15 21:48:51

activityImageView.frame = CGRectZero; 更改

为某个自定义框架。

例如:

activityImageView.frame = CGRectMake(0,0,100,100);

Change activityImageView.frame = CGRectZero;

to some custom frame.

eg:

activityImageView.frame = CGRectMake(0,0,100,100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文