【问题标题】:UIImageView backgroundColor colorWithPatternImage not showingUIImageView backgroundColor colorWithPatternImage 不显示
【发布时间】:2012-01-26 21:21:28
【问题描述】:

我遇到了一个对我来说不太有意义的 UIImageView 问题。我想设置 UIImageView 的图像并让它出现在我设置为背景的图案图像上方。如果背景颜色是标准颜色:[UIColor whiteColor],则会正确发生这种情况,但是一旦将其设置为 patternImage,背景就会变得完全透明。这有点令人沮丧。我可以通过创建另一个视图来解决它,将它的 backgroundColor 设置为 patternImage,然后将 UIImageView 添加为子视图,但这会创建一个不必要的额外视图,IMO。这是我的代码:

UIImageView *view = [[UIImageView alloc] initWithFrame:_standardRect];
view.image = _connectIcon;
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"background.jpg"]];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
return view;

【问题讨论】:

    标签: ios uiimageview


    【解决方案1】:

    在 iOS 5.1 上执行此操作:

    view.layer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"background.jpg"]].CGColor;
    

    但是,该错误在 iOS 6 上消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多