实现基本交互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:一个点击拖拽或者操作一个区域,产生一系列的值
运行结果如下图只用用手触摸按钮就会出发一个事件:
@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] 使用WebViewJavascriptBridge实现OC与JS交互
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- iOS开发使用WebViewJavascriptBridge实现OC与JS交互
- 实现OC与JS的交互
- 实现OC与JS的交互
- iOS使用WebViewJavascriptBridge实现OC与JS交互
- JS与iOS交互之OC获取JS内容跳转到指定控制器实现技巧
- OpenGL+Qt界面(三) Qt中实现OPENGL的基本交互+代码
- 通过WebViewJavascriptBridge实现OC与JS交互
- [iOS] 使用WebViewJavascriptBridge实现OC与JS交互
- 通过WebViewJavascriptBridge实现OC与JS交互
- 移动开发之iOS基础开发(二)实现基本的简单交互
- 排序算法的基本思想和OC代码实现
- iOS下Hybird实现---OC与JS交互以及swift与JS交互
- UIWebView-JSContext实现OC与JS交互
- iOS中HTML与OC的交互实现
- 使用JavaScriptCore实现OC和JS交互详解
- 通过WebViewJavascriptBridge实现OC与JS交互
- Mac Webview OC与JS交互实现