gpt4 book ai didi

ios - 按钮标题文本不清晰

转载 作者:行者123 更新时间:2023-12-01 18:06:49 24 4
gpt4 key购买 nike

我有 BtnDate按钮,单击时, Action 起作用并通过弹出窗口获取当前日期并添加到 BtnDate.titleLabel.text当我在我的 btnAddForm 中使用时检查是否 _myText 的操作大于 > 0清除 _BtnDate.titleLabel.text
但它并没有清除 titleLabel文本字符串。

我的代码如下。

我想要,如果用户输入 _myText _BtnDate 的内部 > 0 值为空。

我的整个代码如下:

.h 文件里面:

@property (nonatomic,retain) IBOutlet UIButton* BtnDate;

.m 文件里面:
    - (void)viewDidLoad
{
[super viewDidLoad];


[_BtnDate addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
_BtnDate.titleLabel.font = [UIFont systemFontOfSize:17];
[[_BtnDate layer] setBorderWidth:1];
[[_BtnDate layer] setCornerRadius:5];
[[_BtnDate layer] setBorderColor:[UIColor lightGrayColor].CGColor];
[_BtnDate setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:_BtnDate];


}


-(void) showDateView{

viewBack2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[viewBack2 setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]];
[self.view addSubview:viewBack2];


dateView = [[UIView alloc] initWithFrame:CGRectMake((viewBack2.frame.size.width-300)/2, (viewBack2.frame.size.height-350)/2, 300, 350)];
[self.view addSubview:dateView];

UIImageView *imageBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg-popup"]];
[imageBackground setFrame:CGRectMake(0, 0, 300, 350)];
[dateView addSubview:imageBackground];
[imageBackground release];

UIButton *BtnDate = [UIButton buttonWithType:UIButtonTypeCustom];
[BtnDate setBackgroundImage:[UIImage imageNamed:@"okay.png"] forState:UIControlStateNormal];
[BtnDate addTarget:self action:@selector(btnDateAction:) forControlEvents:UIControlEventTouchUpInside];
[BtnDate setFrame:CGRectMake(80, 300, 140, 36)];
[dateView addSubview:BtnDate];


datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(25,25, 250, 250)];
datePicker.datePickerMode = UIDatePickerModeDate;

datePicker.hidden = NO;
datePicker.date = [NSDate date];
[datePicker addTarget:self
action:@selector(changeDateInLabel:)
forControlEvents:UIControlEventValueChanged];
[dateView addSubview:datePicker];



}


- (void)changeDateInLabel:(id)sender{

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd"];
if (_BtnDate.selected==true) {
[_BtnDate setTitle:[NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]] forState:UIControlStateNormal];
}

[df release];
}


-(IBAction)btnDateAction:(id)sender{

if (_BtnDate.selected==true) {
_BtnDate.selected=false;
}

[dateView removeFromSuperview];
[viewBack2 removeFromSuperview];


}



- (void) buttonPressed:(UIButton*)sender {

if (sender == _BtnDate) {

[self showDateView];
_BtnDate.selected=true;
}


}


- (IBAction)btnAddForm:(id)sender {


// I WANT TO CHECK _myText if is not null or > 0 must be clear _BtnDate.titleLabel.text dont do this !


if ([NSNumber numberWithInt:[_myText.text intValue]] > 0 ) {

_BtnDate.titleLabel.text = @"";


}
}


- (void)dealloc {
[_myText release];
[_BtnDate release];
[super dealloc];
}
- (void)viewDidUnload {
[self setmyText:nil];
[self setBtnDate:nil];
[super viewDidUnload];
}

最佳答案

当您点击 btnAddForm
设置这个

[BtnDate setTitle:@"" forState:UIControlStateNormal];

关于ios - 按钮标题文本不清晰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40844440/

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