标签: contentmode

138
推荐指数
3
解决办法
9万
查看次数

UIButton不听内容模式设置?

firstButton是Custom类型的UIButton.我以编程方式将三个放在一个表的每个单元格中,因此:

[firstButton setImage:markImage forState:UIControlStateNormal];
[firstButton setContentMode:UIViewContentModeScaleAspectFit];
[cell.contentView addSubview:firstButton];
Run Code Online (Sandbox Code Playgroud)

在其他地方,我告诉它clipToBounds.我得到的是图像中心方块的裁剪,而不是它的纵横比例渲染.我已经尝试了很多方法,包括在firstButton.imageView上设置mode属性,这似乎也不起作用.

uibutton contentmode ios

89
推荐指数
6
解决办法
5万
查看次数

iOS SDK UIViewContentModeScaleAspectFit与UIViewContentModeScaleAspectFill

我有一个图像,我希望UITableViewCell使用UITableViewCellStyleSubtitle提供一个UIImageView和两行文本的样式,以及一个可选的附件视图显示.

但是,当我设置的内容模式UIImageView,以任一UIViewContentModeScaleAspectFit或者UIViewContentModeScaleAspectFill,它似乎没有什么区别.这两种内容模式都只显示整个图像,将文本向右移动以为图像腾出空间.

有没有人在实践中有任何实际差异的例子?文档说:

UIViewContentModeScaleAspectFit:
Scales the content to fit the size of the view by maintaining the aspect ratio. Any     remaining area of the view’s bounds is transparent.

UIViewContentModeScaleAspectFill:
Scales the content to fill the size of the view. Some portion of the content may be  clipped to fill the view’s bounds.
Run Code Online (Sandbox Code Playgroud)

但是这些内容模式似乎没有像宣传的那样表现.

编辑:我正在运行SDK iOS 4.

iphone objective-c uiimageview contentmode ios4

16
推荐指数
2
解决办法
3万
查看次数

如何将Auto Layout约束与UIView的contentMode属性相结合

我有一个UIImageView配置了自动布局的对象.我创建了约束,以便视图与其superview保持恒定的距离.在视觉格式中它将是:

@"V:|-[imageView]-|"
@"H:|-[imageView]-|"
Run Code Online (Sandbox Code Playgroud)

但我还想保留底层图像的宽高比,所以我已经分配UIViewContentModeScaleAspectFit给了contentMode.

我认为一切都运行良好,直到我设置相关的cornerRadiusCALayer:

self.imageView.layer.cornerRadius = 7;
self.imageView.layer.maskToBounds = YES;
Run Code Online (Sandbox Code Playgroud)

现在,当调整图像视图的大小时,例如由于方向的改变,圆角会根据视图获得的新大小而丢失.原因是cornerRadius适用于UIImageView(下面的破折号中的框架),但由于底层图像也调整为尊重contentMode(下面的星号中的框架),因此圆角不再可见:

--------------------------
|       **********       |
|       *        *       |
|       *        *       |
|       *        *       |
|       **********       |
--------------------------
Run Code Online (Sandbox Code Playgroud)

有没有办法防止这种行为?

cornerradius contentmode ios autolayout

14
推荐指数
2
解决办法
5563
查看次数

UIButton突出显示时忽略contentMode(adjustsImageWhenHighlighted)

UIImage为我的UIButton 设置了一个[ myButton setImage:forState:]; 和我设置它contentMode使用[[myButton imageView] setContentMode:UIViewContentModeScaleAspectFit]; 但是当你点击按钮时,它会回到UIViewContentModeScaleToFill并拉伸我的图像.

使用adjustsImageWhenHighlighted修复这个,但后来我松了变暗效果,我想保留.

有关如何应对此问题的任何建议?

scaling image uibutton contentmode ios

12
推荐指数
1
解决办法
4099
查看次数

iOS >> UIButton ImageView属性>>如何设置内容模式?

有没有办法设置UIButton图像,BackgroundImage或ImageView属性内容模式属性?

我尝试过直接的方法(它当然不起作用......):

self.imageButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
Run Code Online (Sandbox Code Playgroud)

有一个带图像的按钮很好,但如果没有办法正确设置它,它不是很方便...

uibutton uiimageview contentmode ios

10
推荐指数
2
解决办法
8089
查看次数

UIViewContentMode模式指的是什么类型的内容?

根据UIView关于该contentMode物业的官方文件:

The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change
Run Code Online (Sandbox Code Playgroud)

什么定义了这个定义中的内容?它是子视图还是我们为视图定义背景颜色时的示例.

我的第一个猜测是它应该至少应用于视图中的子视图,但是例如下面的代码片段在使用UIViewContentModeCenter标记时不会给我预期的结果 :

 UIView* redView = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 150, 200)];
 redView.contentMode = UIViewContentModeCenter;
 redView.backgroundColor = [UIColor redColor];

 UIView* greenView = [[UIView alloc] initWithFrame:redView.bounds];
 greenView.backgroundColor = [UIColor greenColor];
 [redView addSubview:greenView];

 redView.frame = CGRectInset(redView.frame, -5, -5);
 [self.view addSubview:redView];
Run Code Online (Sandbox Code Playgroud)

我刚刚设置了一个包含greenView的redView.我还设置了redview的内容模式UIViewContentModeCenter- 为什么在我编写的代码中,当我更改其父级的框架时,greenView不居中?不应UIViewContentModeCenter该做什么?

谢谢你的澄清!

Ps:您可以在loadView简单的视图控制器模板项目中轻松测试上述代码.

uiview contentmode ios5 uiview-hierarchy

8
推荐指数
2
解决办法
8424
查看次数

8
推荐指数
0
解决办法
2502
查看次数

UIImageView阴影和方面填充在一起

我有一个UIImageView动态设置图像(从URL).图像可以具有任意尺寸/纵横比.我设置contentMode看点填充和视图的图层clipsToBoundsYES,它的正确显示.但是,我还想在图像视图下显示阴影.当我设置阴影图像视图的层上,我需要设置clipsToBoundsNO为阴影来显示,这会导致图像的出血部分从要被显示的视图.如何保持图像视图大小不变(纵横填充)并同时启用阴影?

一个选项可能涉及创建图形上下文并将图像重新绘制到该上下文中,获得具有所需宽高比的图像并将该图像设置为我的图像视图的图像,但这是额外的处理/浪费CPU/GPU和普通世界时间(特别是如果我有大量具有大图像的图像视图).

另一个选项可能涉及创建与我的图像视图大小相同的空白视图,将其插入我的超视图中的视图下方,使用约束动态地将其附加到我的视图,以及在该视图的图层上启用阴影.这还涉及为阴影创建额外的视图.可能是比第一个更好/更有效的解决方案,但仍然是额外的工作(CPU方面).

是否有任何选项不需要额外的工作,可以在我的条件下启用阴影和方面拟合?

calayer uiview uiimageview contentmode ios

6
推荐指数
1
解决办法
683
查看次数

更改固定视图大小的内容模式时的动画

我正在开发一个iPhone应用程序.我有一个UIImageView,其大小固定为320x480.最初,contentmode设置为AspectFit.当我将内容模式更改为Aspect Fill时,我想显示动画(图像的绘图框架发生变化,UIImageView框架被修复).我该怎么做呢?

谢谢和问候,Deepa

iphone animation uiimageview contentmode

5
推荐指数
0
解决办法
461
查看次数