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

03-31 06:12