Friday, 26 October 2012

Hide keyboard programmatically in iOS

1. Add the following code to the implementation file (.m)

-(void) textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
}

And in the header file (.h)
-(void)textFieldShouldReturn:(UITextField *)textField

2. Add target to the textField:
txtField.delegate = self;
[txtField addTarget:self action:@selector(textFieldShouldReturn:)
          forControlEvents:UIControlEventTouchCancel];

That's it! Test it out. Hope you find this useful. 



Adding Customized Font in iOS Project

1. Download your custom font file, and add it to the Xcode project.

2. In the project.plist file, add a row, type in "Fonts provided by application ", and int the item row,
write your desired name.










3. And don't forget to check the target membership. 

Then you can use it whenever you want by:

textField.font =[UIFont fontWithName:@"HelveticaRoundedLTStd-Bd" size:12];

If you are not sure about the font name, you can open the font file in FontForge and check.

But be warned if you added more than 2 custom fonts from the same family, because iOS does not allow to do that. In that case, you can find a solution here.