UiTextfield的底边

时间:2016-07-29 05:44:03

标签: ios objective-c uitextfield

实际上我已经使用此代码在Textfiled中创建了Border。

 CALayer *bottomBorder = [CALayer layer];

bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.layer.frame.size.width, 1.0f);

bottomBorder.backgroundColor = self.BorderColor.CGColor;

[self.layer addSublayer:bottomBorder];

一切正常工作到iphone 5s但是当我在iphone 6及以上版本中运行时它的边框尺寸减小了。就像文本字段的宽度是120边框只显示高达100。不知道该如何应对。请引导我通过它

3 个答案:

答案 0 :(得分:2)

如果您想处理CALayer,请尝试以下生命周期方法。

-(void)viewDidLayoutSubviews
{
    CALayer *bottomBorder = [CALayer layer];
    bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.layer.frame.size.width, 1.0f);
    bottomBorder.backgroundColor = self.BorderColor.CGColor;
    [self.layer addSublayer:bottomBorder];
}

答案 1 :(得分:0)

将边框图层存储在实例变量中,并在- (void)layoutSubviews() { [super layoutSubviews]; bottomBorder.frame = CGRectMake(0.0f, self.frame.size.height - 1, self.layer.frame.size.width, 1.0f); } 中更新其框架。

$(document).ready(function () {
   closefancybox();
});

function closefancybox() {
    $.fancybox({
        afterLoad: function () {$.fancybox.close();}
    });
    setTimeout(function () { closefancybox(); }, <time_inter>);
}

答案 2 :(得分:0)

创建一个函数,然后调用你想要的地方。

 -(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self setBottomBorder:self.txtfield];
}
-(void)setBottomBorder:(UITextField*)textfield
{
    //bottom border
    CALayer *BottomBorder = [CALayer layer];
    BottomBorder.frame = CGRectMake(0.0f, textfield.frame.size.height-1, textfield.frame.size.width, 1f);
    BottomBorder.backgroundColor =GreenColor.CGColor;

    [textfield.layer addSublayer:BottomBorder];
}