Placeholder in UITextView

前端 未结 30 3125
野趣味
野趣味 2020-11-22 16:01

My application uses an UITextView. Now I want the UITextView to have a placeholder similar to the one you can set for an UITextField.<

30条回答
  •  旧巷少年郎
    2020-11-22 16:07

    Lets make it easy

    Create one UILabel and place it on your text view(Give the text as Placeholder-set color gray-you can do all this in your xib) Now in you header file declare the UILabel and also the the textviewDelegate Now you can simply hide the label when you click on the textview

    complete code below

    header

    @interface ViewController :UIViewController{
     }
       @property (nonatomic,strong) IBOutlet UILabel *PlceHolder_label;
       @property (nonatomic,strong) IBOutlet UITextView *TextView;
    
    @end
    

    implementation

    @implementation UploadFoodImageViewController
    @synthesize PlceHolder_label,TextView;
    
      - (void)viewDidLoad
        {
           [super viewDidLoad];
        }
    
    
     - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
           if([textView isEqual:TextView]){
                [PlceHolder_label setHidden:YES];
                [self.tabScrlVw setContentOffset:CGPointMake(0,150) animated:YES];
              }
          return YES;
        }
    

    @end

    Dont forget to connect the textView and UILabel to filesowner from xib

提交回复
热议问题