I face a very strange UIButton problem. When I press the button and move (do not release), the highlighted area goes to wrong areas (areas that beyond the scope of the view). However, the key inside up event works. Can anyone help?
Declaration:
Definition:
Use:
Declaration:
Code:
@interface datapickerForDayViewController : UIViewController
{
UIDatePicker *datePicker;
UIButton *button;
}
@property ( nonatomic, retain ) IBOutlet UIDatePicker *datePicker;
@property ( nonatomic, retain ) IBOutlet UIButton *button;;
-(IBAction)buttonPressed: (id)sender;
-(id)initMyFrame:(CGRect)_rect;
@end
Code:
@implementation datapickerForDayViewController
@synthesize datePicker;
@synthesize button;
-(id)initMyFrame:(CGRect)_rect
{
self.view.frame=_rect;
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, _rect.size.width, (_rect.size.height/2))];
datePicker.datePickerMode=UIDatePickerModeDate;
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.button = myButton;
button.frame = CGRectMake((_rect.size.width/4), (_rect.size.height *2/3), (_rect.size.width/2), (_rect.size.height/6));
[button setTitle:@"Select Date" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:datePicker];
[self.view addSubview:button];
return self;
}
-(IBAction) buttonPressed: (id)sender
{
...
}
@end
Code:
datapickerForDayViewController* myDatePickController=[[datapickerForDayViewController alloc] initWithNibName:nil bundle:nil];
[myDatePickController initMyFrame:CGRectMake(410, 185, 572, 535)];
[superview addSubview:myDatePickController.view];