我有BtnDate
按鈕,點擊後行爲作品,並得到當前的日期與彈出窗口並增加內部BtnDate.titleLabel.text
,當我用我的行動btnAddForm
裏面,以檢查是否_myText
是大於> 0
明確_BtnDate.titleLabel.text
按鈕標題文字不清晰
但它不清除titleLabel
文本字符串。
我的代碼如下。
我想要的,如果用戶條目_myText
裏面> 0的值爲_BtnDate
爲空。
我的整個代碼如下:
的.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];
}
@Rajat在那裏我會增加嗎? TY – SwiftDeveloper