顯示具有 Objective-c 標籤的文章。 顯示所有文章
顯示具有 Objective-c 標籤的文章。 顯示所有文章

2014年9月24日 星期三

Xcode 6.0.1 / iOS 8 UIAlertController

UIAlertControllerStyleAlert with Buttons

UIAlertController  *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
   
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel Action");
        }];
   
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Delete Action");
}];

[alertController addAction:cancelAction];
[alertController addAction:deleteAction];

[self presentViewController:alertController animated:YES completion:nil];

2014年9月10日 星期三

iOS set UIImageView to CircleView


- (id)imageViewSetCornerRadius:(UIImageView *)imageView withImage:(UIImage *)image {
    
    imageView.image = image;
    imageView.layer.borderWidth = 3.0f;
    imageView.layer.borderColor = [UIColor whiteColor].CGColor;
    imageView.layer.cornerRadius = imageView.frame.size.width / 2;
    imageView.clipsToBounds = YES;
    
    return imageView;
}

2014年7月13日 星期日

[iOS] Objective-c sharedApplication delegate, global @property



AppDelegate.h

#define appDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])


@property (nonatomic, assign)NSInteger globalCount;


How to use?

2014年6月20日 星期五

[iOS] Objective-c save/load image under APP document

Objective-c save/load image under APP document

Save image: 
   [self saveImageInDocumenet:Image withName:@"blue"];

Load image with name: 
   UIImage *image = [self loadImageFromDocumentWithName:@"blue"];


- (void)saveImageInDocumenet:(UIImage *)image withName:(NSString *)name {
    
    if (image != nil) {
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:name];

        NSData* data = UIImagePNGRepresentation(image);
        [data writeToFile:path atomically:YES];

    }
}

[iOS] Objective-c NSString to Hex string

Objective-c NSString to Hex string


NSData *data = [self parseMacAddress:@"AABBCCDDEEFF "];

NSLog(@"After transfer: %@", data); 
= > AABBCCDDEEFF (Hex)