Showing posts with label UITextView. Show all posts
Showing posts with label UITextView. Show all posts

Wednesday, March 30, 2011

How to Change UITextView Background Color

You have UIView, which contains UITextView with some text. This is how to change UITextView background color:
self.view.opaque = YES;
self.view.backgroundColor = [UIColor yellowColor];
self.textView.opaque = NO;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.textColor = [UIColor orangeColor];
Not what I was looking for, but might as well write down, looks useful enough. Another tool in the toolbox, even though everything still looks like a nail.

Sunday, November 21, 2010

How to Disable Copy, Paste and Select for UITextView

Need to use UITextView, but don't want Copy, Paste and Select feature. How to disable that? Tried overwriting canPerformAction:withSender but I got still a flash of quickly disappearing popup menu and selection.

Subclass UITextView and overwrite canBeforeFirstResponder to return always NO:
@interface MyUITextView : UITextView
@end
@implementation MyUITextView
- (BOOL)canBecomeFirstResponder
{
   return NO;
}
@end
Now you have completely hidden and disabled copy, paste and select for UITextView!

Thursday, October 7, 2010

How to Get Rid of Keyboard with a Tap on Background part2

There was a nice way to remove keyboard by using UITextView, but that has stopped working with iOS4. At least I got such a defect report for beta application. This time I will remove keyboard using UIButton, let's see how long that will work:
- (IBAction)removeKeyboard
{
    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];
}
Open your view in Interface Builder, create new custom full screen UIButton to cover everything, select UITextFields and UIButtons (etc.) one by one and "Send to Front" via Layout menu. Connect UIButton "Touch Up Inside" to your callback and that's it.

Nice, easy, simple, fast - what more can you ask for!

Monday, April 26, 2010

How to Get Rid of Keyboard with a Tap on Background

There is a screen with a couple of UITextFields and UIButtons. When user taps on UITextField, keyboard popups. Very nice of iPhone SDK to provide such a feature! Each UITextField and UIButton is a clickable object with easy callbacks.

But how do you get rid of keyboard?

Should you have a special "Please hide keyboard" button or tap into accelerometer to notice when user gets desperate enough to start shaking the device? There's an easier way...

Add a full-screen empty non-editable UITextView over the whole screen. Select each clickable object e.g. UITextField, UIButton or other UITextViews and use Interface Builder menu item Layout - Send to Front to place them on top of your full-screen UITextField.

When user clicks on anywhere except your clickable objects, keyboard disappears. What a relief!

Please note that, if you leave any non-clickable objects e.g. UILabel on top of your full-screen UITextView, clicking on those spots will not hide keyboard.