【非凡程序员】 OC第十六节课 初识OS X开发一(字母大小写转换)

OS X开发就是苹果电脑上的界面开发:与之前学习OC最大的区别是有了界面,不只是一个输出的框。利用拖界面而自动创建IBOutlet NSTextField和(id)sender类型。

 

ViewController.h文件:

#import <Cocoa/Cocoa.h>

@interface ViewController : NSViewController

@property (weak) IBOutlet NSTextField *weizimu;
@property (weak) IBOutlet NSTextField *shouzimu;
@property (weak) IBOutlet NSTextField *xiaoxie;
@property (weak) IBOutlet NSTextField *daxie;
@property (weak) IBOutlet NSTextField *string;

- (IBAction)change:(id)sender;
@end

ViewController.m文件:

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view.
}

- (void)setRepresentedObject:(id)representedObject {
    [super setRepresentedObject:representedObject];

    // Update the view, if already loaded.
}

- (IBAction)change:(id)sender {
    NSLog(@"%@",[ _string stringValue]);  
    NSLog(@"%@",[ _string stringValue] lowercaseString]);
    NSLog(@"%@",[ _string stringValue] uppercaseString]);

   //  (通过setStringValue进行设置输出)-----(重点)

    [_daxie setStringValue:[[_string stringValue] uppercaseString]];
    [_xiaoxie setStringValue:[[_string stringValue] lowercaseString]];
    [_shouzimu setStringValue:[[_string stringValue] capitalizedString]];

   
    NSRange range=NSMakeRange([[_string stringValue] length]-1,1);
    NSMutableString *xiao=[NSMutableString stringWithFormat(@"%@",[ _string stringValue] lowercaseString]];

    [_weizimu setStringValue:[[xiao substringWithRange:range]capitalizedString]];
    [xiao replaceCharactersInRange:range withString:[[xiao substringWithRange:range]capitalizedString]];
    [_weizimu setStringValue:xiao];

}
@end

你可能感兴趣的:(非凡程序员)