前言
我们已经初步使用了,但是和页面并没有交互,并不直观,接下啦我们写和UI交互相关的代码
效果 E549927C167F099E4587C366CE969F8D.jpg
代码
#import <UIKit/UIKit.h>
@interface FindViewController
@property (nonatomic, strong) UIView* view;
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion;
- (void)btnDidClicked;
@end
%hook FindCell
- (void)setImageV:(id *)imageV{};
- (void)setLabel:(id *)label{
NSLog(@"你是不是傻");
};
%end
%hook FindViewController
- (void)tableView:(id)arg1 didSelectRowAtIndexPath:(id)arg2 {
NSLog(@"你是一个傻子");
}
- (void)viewDidLoad {
%orig;
CGFloat x = 50.0f;
CGFloat y = 100.0f;
UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, self.view.frame.size.width-x*2, 50)];
[self.view addSubview:btn];
[btn setTitle:@"back" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor blueColor];
[btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnDidClicked) forControlEvents:UIControlEventTouchUpInside];
}
%new
- (void)btnDidClicked {
UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"提示"
message:@"已经被HOOK了"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消"
style:UIAlertActionStyleCancel
handler:nil];
[alerView addAction:cancelAction];
[self presentViewController:alerView animated:YES completion:nil];
}
%end
网友评论