您好,我正在开发 iPhone 应用程序,我在其中尝试为 edittext 设置一侧边框.我是通过以下方式做到的:
Hi I am developing iPhone application in which I tried to set one side border for edittext. I did this in following way:
int borderWidth = 1;
CALayer *leftBorder = [CALayer layer];
leftBorder.borderColor = [UIColor whiteColor].CGColor;
leftBorder.borderWidth = borderWidth;
leftBorder.frame = CGRectMake(0, textField.frame.size.height - borderWidth, textField
.frame.size.width, borderWidth);
[textField.layer addSublayer:leftBorder];
我在 IB 中对我的 edittext 设置了一些限制,这样当我旋转我的设备时,它会据此调整文本字段的宽度.我的问题是调整edittext的宽度而不是调整我为编辑文本设置的CALayer的宽度.所以我想我也必须为我的 CALayer 项目设置一些限制.但我不知道该怎么做.任何人都知道这件事吗?需要帮忙.谢谢.
I put some constraints on my edittext in IB so that when I rotate my device it will adjust width of text field according to that. My problem is that adjusts the width of edittext not adjusting the width of CALayer which I set for my edit text. So I think I have to put some constraints for my CALayer item as well. But I dont know how to do that. ANy one knows about this? Need Help. Thank you.
整个自动调整大小业务是特定于视图的.图层不会自动调整大小.
the whole autoresizing business is view-specific. layers don't autoresize.
你必须做的——在代码中——是自己调整层的大小
what you have to do -- in code -- is to resize the layer yourself
例如
在 viewController 中你会这样做
in a viewController you would do
- (void) viewDidLayoutSubviews {
[super viewDidLayoutSubviews]; //if you want superclass's behaviour...
// resize your layers based on the view's new frame
self.editViewBorderLayer.frame = self.editView.bounds;
}
或者在你可以使用的自定义 UIView 中
or in a custom UIView you could use
- (void)layoutSubviews {
[super layoutSubviews]; //if you want superclass's behaviour... (and lay outing of children)
// resize your layers based on the view's new frame
layer.frame = self.bounds;
}
这篇关于CALayer IOS上的自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!