Showing posts with label background. Show all posts
Showing posts with label background. Show all posts

Sunday, June 2, 2013

UITextField background example in Objective C (iOS).


UITextField background

The image that represents the background appearance of the text field when it is enabled.

@property(nonatomic, retain) UIImage *background

Discussion of [UITextField background]
When set, the image referred to by this property replaces the standard appearance controlled by the borderStyle property. Background images are drawn in the border rectangle portion of the image. Images you use for the text field’s background should be able to stretch to fit.

This property is set to nil by default.

UITextField background example.
#pragma mark -
#pragma mark UITextFieldDelegate methods

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    _field.background = [UIImage imageNamed:@"focus.png"];
    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    _field.background = [UIImage imageNamed:@"nofocus.png"];
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

Example of [UITextField background].
- (BOOL)becomeFirstResponder {
    BOOL outcome = [super becomeFirstResponder];
    if (outcome) {
      self.background = // selected state image;
    }
    return outcome;
}

- (BOOL)resignFirstResponder {
    BOOL outcome = [super resignFirstResponder];
    if (outcome) {
      self.background = // normal state image;
    }
    return outcome;
}

UITextField background example.
        [YourTextFiled setFont:[UIFont systemFontOfSize:18]];
        YourTextFiled.textAlignment = UITextAlignmentLeft;
        YourTextFiled.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
        YourTextFiled.leftViewMode = UITextFieldViewModeAlways;
        YourTextFiled.background = [[UIImage imageNamed:@"xFOEr.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];

End of UITextField background example article.

Friday, May 6, 2011

Background method execution using NSThread code example objc

You can execute a method in background mode using detachNewThreadSelector method. For proper memory management, the target method maintains its own AutoreleasePool. [detachNewThreadSelector]


[NSThread detachNewThreadSelector:@selector(doSomethingInBack:) toTarget:self withObject:nil];

-(void) doSomethingInBack:(id)anObject {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
// 다른 스레드로 실행할 코드 작성.p
[NSThread exit];
// 메모리 릭 방지.
[autoreleasepool release];
}