Reputation: 6386
I am having a uitexview in that would like to have uibutton.when tapping on that button i want do some actions.So i did as below
UITextView *myTextView = [[UITextView alloc] init];
myTextView.frame = CGRectMake(10, 100, 300, 80);
myTextView.layer.borderWidth = 1.0f;
myTextView.layer.cornerRadius = 5;
myTextView.clipsToBounds = YES;
myTextView.layer.borderColor = [[UIColor grayColor] CGColor];
[self.view addSubview:myTextView];
[myTextView sizeToFit];
[myTextView release];
// Create an UIButton
UIButton *pickerBtn = [UIButton buttonWithType: UIButtonTypeCustom];
// Set its background image for some states...
UIImage *pickerImage = [UIImage imageNamed:@"picker.png"];
[pickerBtn setBackgroundImage: pickerImage forState:UIControlStateNormal];
// Add target to receive Action
[pickerBtn addTarget: self action:@selector(showPicker:) forControlEvents:UIControlEventTouchUpInside];
// Set frame width, height
pickerBtn.frame = CGRectMake(-25, -10, 50, 30);
pickerBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
pickerBtn.titleLabel.font = [UIFont boldSystemFontOfSize:13];
pickerBtn.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
pickerBtn.titleLabel.shadowOffset = CGSizeMake(0, -1);
pickerBtn.bounds = CGRectInset(button.bounds, -3, 2);
pickerBtn.titleLabel.textColor = [UIColor whiteColor];
[myTextView addSubview:pickerBtn];
But what my problem is cursor shows even on that button.
Is there any better way to do wat i am trying now
Please let me know and thanks
Upvotes: 0
Views: 1547
Reputation: 1693
You have to measure the length of the text and put the button at the end text and when click on the show the picker and append the text. i think this is way you can do.
Upvotes: 1