Cocoa®programming for Mac®os X (2)-Speak line

Source: Internet
Author: User

1. NSControl is the parent of all controls, NSControl inherits from NSView, so nscontrol is a nsview that can respond to events independently, each nscontrol containing a target and action, The action message is sent when the user interacts with the control.

One thing you don't understand is that most of the controls in iOS have been notified to the caller by the method that called the corresponding protocol, and NSControl has only one action, which is understandable for a button, and how should it respond to a table?

  

2. Implement Speakline Demo

  

Create a new empty project, automatically set up a window in the project

Create a new Viewcontroller and add Viewcontroller.view to the Contentview of the window

The code is as follows:

Appdelegate:

-(void) applicationdidfinishlaunching: (nsnotification *) anotification {    //    [Self.window SetBackgroundColor : [NSColor Redcolor]];        _SPVC = [[Spviewcontroller alloc] initwithnibname:@ "Spviewcontroller" bundle:nil];    _spvc.view.frame = nsmakerect (0, 0, self.window.frame.size.width, self.window.frame.size.height);    _spvc.view.autoresizingmask = nsviewwidthsizable| nsviewheightsizable;    [Self.window.contentView Addsubview:_spvc.view];     Self.window.title = @ "Speak line";    }

VC corresponding to the code:

#import "SPViewController.h" @interface Spviewcontroller () @property (weak) Iboutlet Nstextfield *speaktextfield;@ Property (Nonatomic, Strong) Nsspeechsynthesizer *speechsynth; @end @implementation spviewcontroller-(void) viewdidload {    [super viewdidload];    Do view setup here.    _speechsynth = [[Nsspeechsynthesizer alloc] init];} -(Ibaction) STOP: (ID) Sender {    [_speechsynth stopspeaking];} -(Ibaction) Speak: (ID) Sender {        if (_speaktextfield.stringvalue.length > 0)    {        [_speechsynth Startspeakingstring:_speaktextfield.stringvalue];    }    } @end

  

Code Address: http://pan.baidu.com/s/1ntpAR37

Cocoa®programming for Mac®os X (2)-Speak line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.