4

UIActionSheet for two UITextView

 2 years ago
source link: https://www.codesd.com/item/uiactionsheet-for-two-uitextview.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

UIActionSheet for two UITextView

advertisements

I have a UIActionSheet to change font of a UITextView. The problem I have is that I have added another UITextView and now wants that it depends on the open UITextView, (I mean open to edit, showing the keyboard) assign me the type of source in one or the other... not be which is the correct property of the UITextView in order to differentiate one from the other depending on the selection.

any idea?

This is the case of a single UITextView.

- (IBAction) displayFontPicker:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select a font" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Helvetica", @"Courier", @"Arial", @"Zapfino", @"Verdana", nil];
[actionSheet showFromBarButtonItem:(UIBarButtonItem *)sender animated:YES];

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *selectedButtonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
selectedButtonTitle = [selectedButtonTitle lowercaseString];

if ([actionSheet.title isEqualToString:@"Select a font"])
switch (buttonIndex){

    case 0:

        [_textView setFont:[UIFont fontWithName:@"Helvetica" size:25]];

        break;
    case 1:

        [_textView setFont:[UIFont fontWithName:@"Courier" size:25]];

        break;
}

I'm seeing that using the textview , can use a number of methods, in particular this could use it, will run when you start to edit a textview.

(void)textViewDidBeginEditing:(UITextView *)textView

But I don't know how to implement it in my code...


You can apply tag for each UITextView by setting setTag property and can differentiate between both. add property to check which textView is in editable state

@property NSInteger editabelTextView;

Now allocation all UITextView and add tags for each UITextView.

self.textView1 = [[UITextView alloc] init];
self.textView2 = [[UITextView alloc] init];
self.textView3 = [[UITextView alloc] init];

self.textView1.tag = 1;
self.textView2.tag = 2;
self.textView3.tag = 3;

and now assign textView.tag to self.editabelTextView

-(void)textViewDidBeginEditing:(UITextView *)textView
{
  self.editabelTextView=textView.tag;
}

now check self.editabelTextView and accrodingly setFont for specific text view

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex (NSInteger)buttonIndex {
  switch (self.editabelTextView){
  case 1:
      [self.textView1 setFont:[UIFont font...]];
      break;
  case 2:
      [self.textView2 setFont:[UIFont font...]];
      break;
  case 3:
      [self.textView3 setFont:[UIFont font...]]
      break;
  default:
      break;
  }
}




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK