您的位置:首页 > 移动开发 > IOS开发

实现基本交互Oc

2017-07-20 13:42 447 查看
#import <UIKit/UIKit.h>

@interface AppDelegate :
UIResponder <UIApplicationDelegate>

@property (strong,
nonatomic) UIWindow *window;

@end

#import "ViewController.h"

@interface
ViewController ()

@property (weak,
nonatomic) IBOutlet
UILabel *statusLabel;

@end

@implementation ViewController

- (IBAction)buttonPressed:(UIButton *)sender {

   
//通过sender参数获取被点击的按钮的标题

    NSString * title = [sender
titleForState:UIControlStateNormal];

   
//创建一个新的字符串(新的字符串的内容是在上一行代码获取到的按钮标题末尾添加(你最逗!)文本拼接而成的。)

    NSString * plainText = [NSString
stringWithFormat:@"%@
你最逗!",title];

   
//把这个新的字符串赋给标签的text属性,这样就可以改变标签的显示文本

    //_statusLabel.text = plainText;

    NSMutableAttributedString * styledText = [[NSMutableAttributedString
alloc]initWithString:plainText];

    NSDictionary * attributes =@{

                                 NSFontAttributeName : [UIFont
boldSystemFontOfSize:_statusLabel.font.pointSize]

                                 };

    NSRange nameRange =[plainText
rangeOfString:title];

    

    [styledText setAttributes:attributes
range:nameRange];

    _statusLabel.attributedText = styledText;

}

- (void)viewDidLoad {

    [super
viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

- (void)didReceiveMemoryWarning {

    [super
didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc,
char * argv[]) {

    @autoreleasepool {

        return
UIApplicationMain(argc, argv,
nil,
NSStringFromClass([AppDelegate
class]));

    }

}

#import <XCTest/XCTest.h>

@interface ______OCTests :
XCTestCase

@end

@implementation ______OCTests

- (void)setUp {

    [super
setUp];

    // Put setup code here. This method is called before the invocation of each test method in the class.

}

- (void)tearDown {

    // Put teardown code here. This method is called after the invocation of each test method in the class.

    [super
tearDown];

}

- (void)testExample {

    // This is an example of a functional test case.

    // Use XCTAssert and related functions to verify your tests produce the correct results.

}

- (void)testPerformanceExample {

    // This is an example of a performance test case.

    [self
measureBlock:^{

        // Put the code you want to measure the time of here.

    }];

}

@end

#import <XCTest/XCTest.h>

@interface ______OCUITests :
XCTestCase

@end

@implementation ______OCUITests

- (void)setUp {

    [super
setUp];

    

    // Put setup code here. This method is called before the invocation of each test method in the class.

    

    // In UI tests it is usually best to stop immediately when a failure occurs.

    self.continueAfterFailure =
NO;

    // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.

    [[[XCUIApplication
alloc]
init] launch];

    

    // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.

}

- (void)tearDown {

    // Put teardown code here. This method is called after the invocation of each test method in the class.

    [super
tearDown];

}

- (void)testExample {
af50

    // Use recording to get started writing UI tests.

    // Use XCTAssert and related functions to verify your tests produce the correct results.

}

@end



然后是storyboard操作结果图:



TouchDown 是鼠标落下的瞬间立刻产生事件

Sent Events的含义: Did
End On Exit:用户点击return或者done按钮

Editing Changed:字符增减,Cuisor改变位置等

Editing Did Begin:当field得到焦点

Editing Did end:焦点离开field

Touch Cancel:一个系统的事件,取消当前区域的点击操作

Touch Down:一个区域内的touch-down事件

Touch Down Repeat:区域内重复的touch-down事件;UITouch的tapCount方法大于1

Touch Drag Enter:手指拖进入(into)区域内的事件

Touch Drag Exit:手指从区域内拖出边界的事件

Touch Drag Inside:手指在区域内(inside)拖的事件

Touch Up Inside:手指在区域内触发的touch-up事件

Touch Up Outside:按下在区域外结束的事件

Value Changed:一个点击拖拽或者操作一个区域,产生一系列的值

运行结果如下图只用用手触摸按钮就会出发一个事件:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 移动开发