ios - 为什么我的 UIView 中没有显示任何内容?

标签 ios iphone objective-c uiview xcode5

我有以下代码添加了一个 UIView,然后添加了一个 UIImageView 和 UILabel,UIView 显示正确,但我在 View 旁边没有显示任何内容。我到处都看过,但找不到答案。 UIView 在特定条件下呈现,当它被点击时它会消失。

这是我的代码。

UIView *actionView = [[UIView alloc] initWithFrame:CGRectMake(20, 180, 280, 165)];
        UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
        [actionView addGestureRecognizer:singleFingerTap];
        actionView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
        actionView.layer.cornerRadius = 5;
        actionView.layer.masksToBounds = YES;
        [self.view addSubview:actionView];
        UILabel *actionText = [[UILabel alloc] initWithFrame:CGRectMake(20, 180, 280, 165)];
        actionText.text = @"Hello";
        actionText.textColor = [UIColor redColor];
        actionText.textAlignment = NSTextAlignmentCenter;
        [actionText setTextColor:[UIColor redColor]];
        [actionText setBackgroundColor:[UIColor clearColor]];
        [actionText setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
        actionText.Frame = CGRectMake(20, 180, 280, 165);
         [actionView addSubview:actionText];
        UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"trash-icon.png"]];
        UIImageView* blockView = [[UIImageView alloc] initWithImage:image];
        blockView.frame = CGRectMake(109, 273, 40, 40);
      [actionView addSubview:blockView];

最佳答案

改变你的框架位置,比如..

    UILabel *actionText = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 280, 40)];
    actionText.text = @"Hello";
    actionText.textColor = [UIColor redColor];
    actionText.textAlignment = NSTextAlignmentCenter;
    [actionText setTextColor:[UIColor redColor]];
    [actionText setBackgroundColor:[UIColor clearColor]];
    [actionText setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]];
    [actionView addSubview:actionText];

    UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"trash-icon.png"]];
    UIImageView* blockView = [[UIImageView alloc] initWithImage:image];
    blockView.frame = CGRectMake(109,70, 40, 40);
    [actionView addSubview:blockView]; 

关于ios - 为什么我的 UIView 中没有显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20702837/

相关文章:

ios - iphone:这个错误是什么?

iphone - 使用 IP 地址、端口和凭据进行实时视频流监控

ios - 如何创建单独的方法来创建 SKLabelNode 或 SKSpriteNode

ios - 有什么方法可以重置 dequeueReusableAnnotationViewWithIdentifier 中使用的队列吗?

ios - 在 Swift 中设置 AVCaptureSession 中 AVCaptureDevice 的低帧率

ios - 我如何确定我的 Alamofire 请求的优先级,以便它们在函数返回之前执行?

ios - Swift 编程 - 如何设置轮流应用程序

iphone - UIActivityIndi​​cator 没有动画

iphone - UIBarButtonItem 有颜色吗?

ios - iOS 7-10 收到通知时如何显示本地通知?