1.添加 UIButton
[self.contentView addSubview:({
self.button = [[UIButton alloc]initWithFrame:CGRectMake(200, 80, 20, 20)];
// self.rightImgView.contentMode = UIViewContentModeScaleAspectFit;
[self.button setTitle:@"k" forState:UIControlStateNormal];
[self.button setTitle:@"M" forState:UIControlStateHighlighted];
self.button.backgroundColor =[UIColor redColor];
self.button;
})];
2. UIButton 的事件监听
3. UIView 的手势监听
给UIView 注册 UITapGestureRecognizer 的手势监听
//添加一个UIView ,设置UIView的手势监听
UIView *gestureView = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];
gestureView.backgroundColor=[UIColor yellowColor];
UITapGestureRecognizer *recognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMyCustomView)];
[gestureView addGestureRecognizer:recognize];
4. WebView 基础
实现新闻页跳转到对应的网页
- 新建DetailViewControl.m
#import "DetailViewController.h"
#import <WebKit/WebKit.h>
@interface DetailViewController ()
@property(nonatomic,strong,readwrite) WKWebView *webView;
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 88, self.view.frame.size.width, self.view.frame.size.height-88)];
[self.view addSubview: self.webView];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://time.geekbang.org"]]];
}
- 效果图