gpt4 book ai didi

ios - UITextFields 不允许我编辑文本

转载 作者:行者123 更新时间:2023-11-28 21:57:33 26 4
gpt4 key购买 nike

我在我的 iOS 应用程序中以编程方式创建了两个 UITextField,并将它们的文本分别设置为 _minPrice_minPrice 变量。

_minPrice_maxPrice 值在这两个字段中正确显示,但是点击它们不允许用户编辑它们,它们只是保留那些静态值,退格不起作用。我的代码是否有任何内容阻止编辑文本字段?

    // Min Price
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(-25, -76, 70, 30)];
tf.textColor = [UIColor blackColor];
tf.font = [UIFont fontWithName:@"Helvetica-Neue" size:14];
tf.backgroundColor=[UIColor whiteColor];
tf.text= _minPrice;

tf.textAlignment = NSTextAlignmentCenter;
tf.layer.cornerRadius=8.0f;
tf.layer.masksToBounds=YES;
tf.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf.layer.borderWidth= 1.0f;

// Max Price
UITextField *tf1 = [[UITextField alloc] initWithFrame:CGRectMake(100, -76, 70, 30)];
tf1.textColor = [UIColor blackColor];
tf1.font = [UIFont fontWithName:@"Helvetica-Neue" size:14];
tf1.backgroundColor=[UIColor whiteColor];
tf1.text= _maxPrice;

tf1.textAlignment = NSTextAlignmentCenter;
tf1.layer.cornerRadius=8.0f;
tf1.layer.masksToBounds=YES;
tf1.layer.borderColor=[[UIColor lightGrayColor]CGColor];
tf1.layer.borderWidth= 1.0f;

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 400, 400)];
[view addSubview:tf];
[view addSubview:tf1];

[self.view addSubview:view];

最佳答案

您的问题显然是您设置的框架...

将添加标签的 View 的颜色设置为蓝色可以揭示您的问题:

enter image description here

如果您确保标签确实在您添加它们的 View 中(即不是负数),编辑就没问题。我所做的只是将 tf 中的负 x 和 y 值更改为正值,并且它们是可编辑的:

UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(25, 76, 70, 30)];

enter image description here

关于ios - UITextFields 不允许我编辑文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26047989/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com