iOS開發之控制元件帶箭頭的彈出窗
阿新 • • 發佈:2019-02-06
寫了個帶箭頭的彈出檢視的封裝類,介面小夥伴們可以自己進行優化,承載檢視已經暴露出來了應該是很容易修改的,個人感覺常用的效果都已經出來了^_^,有十二個箭頭的位置可自由設定希望對大家有所幫助...
2、效果圖
箭頭在上中效果圖.png
箭頭在上左效果圖.png
3、開啟工程找到類庫的檔案,可以直接拖到自己工程使用

類庫檔案.png
4、在這裡可以看程式碼例項
例項檔案.png
5、程式碼講解
- 程式碼例項
#import "ViewController.h"
#import "WBPopOverView.h"
#define Swith self.view.frame.size.width
#define Sheight self.view.frame.size.height
@interface ViewController ()
@property(strong,readwrite,nonatomic)UIButton *button;
@property(strong,readwrite,nonatomic)NSMutableArray *testArr;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_button=[[UIButton alloc]initWithFrame:CGRectMake (Swith/2-50, 100, 100, 30)];
[_button setTitle:@"測試" forState:UIControlStateNormal];
[_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_button addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
_button.backgroundColor=[UIColor lightGrayColor];
[self.view addSubview:_button];
}
-(void)btnclick
{
CGPoint point=CGPointMake(_button.frame.origin.x+_button.frame.size.width/2, _button.frame.origin.y+_button.frame.size.height);//箭頭點的位置
WBPopOverView *view=[[WBPopOverView alloc]initWithOrigin:point Width:200 Height:300 Direction:WBArrowDirectionUp2];//初始化彈出檢視的箭頭頂點位置point,展示檢視的寬度Width,高度Height,Direction以及展示的方向
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
lable.text=@"測試內容";
lable.textColor=[UIColor whiteColor];
[view.backView addSubview:lable];
[view popView];
}
@end
- 我們初始化彈出檢視時需要彈出檢視“箭頭的頂點位置”、“檢視的寬高”、“箭頭的指向”
- 我們向彈出檢視中新增子檢視可以通過.backView來進行操作
新增子檢視到彈窗.png
- 我們可以在初始化彈出檢視時設定箭頭位置方向,這裡共定義了十二個位置
箭頭方向.png
文/逆襲的小菜鳥(簡書作者)
原文連結:http://www.jianshu.com/p/c762bf00d825
著作權歸作者所有,轉載請聯絡作者獲得授權,並標註“簡書作者”。