iOS開發UI組件騰訊QMUI框架(iOS)介紹
1. 幽靈按鈕的使用
幽靈按鈕效果圖.png
實現上面效果的代碼:
- (void)initSubviews {
[super initSubviews];
self.ghostButton1 = [[QMUIGhostButton alloc]initWithGhostType:QMUIGhostButtonColorBlue];
self.ghostButton1.titleLabel.font = UIFontMake(14);
[self.ghostButton1 setTitle:@"QMUIGhostButtonColorBlue" forState:UIControlStateNormal];
self.ghostButton1.cornerRadius = 20; // 默認為按鈕高度的一半,改變數值以改變圓角大小
[self.view addSubview:self.ghostButton1];
self.ghostButton2 = [[QMUIGhostButton alloc]init];
self.ghostButton2.ghostColor = [UIColor grayColor]; // 自定義幽靈按鈕的顏色(這里不是QMUI的枚舉顏色)
self.ghostButton2.titleLabel.font = UIFontMake(14);
[self.ghostButton2 setTitle:@"QMUIGhostButtonColorRed" forState:UIControlStateNormal];
[self.view addSubview:self.ghostButton2];
self.separatorLayer1 = [QDCommonUI generateSeparatorLayer];
[self.view.layer addSublayer:self.separatorLayer1];
self.separatorLayer2 = [QDCommonUI generateSeparatorLayerColorBlue]; // 如果要改變分割線的顏色,在QDCommonUI文件中添加類對應的方法即可.
[self.view.layer addSublayer:self.separatorLayer2];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGFloat contentMinY = CGRectGetMaxY(self.navigationController.navigationBar.frame);
CGFloat buttonSpacingHeight = 72;
CGSize buttonSize = CGSizeMake(260, 40);
CGFloat buttonMinX = CGFloatGetCenter(CGRectGetWidth(self.view.bounds), buttonSize.width);
CGFloat buttonOffsetY = CGFloatGetCenter(buttonSpacingHeight, buttonSize.height);
self.ghostButton1.frame = CGRectFlatMake(buttonMinX, contentMinY + buttonOffsetY, buttonSize.width, buttonSize.height);
self.ghostButton2.frame = CGRectFlatMake(buttonMinX, contentMinY + buttonSpacingHeight + buttonOffsetY, buttonSize.width, buttonSize.height);
self.separatorLayer1.frame = CGRectMake(0, contentMinY + buttonSpacingHeight - PixelOne, CGRectGetWidth(self.view.bounds), PixelOne);
self.separatorLayer2.frame = CGRectMake(0, contentMinY + buttonSpacingHeight * 2 - PixelOne, CGRectGetWidth(self.view.bounds), PixelOne);
}
還支持設置帶有圖片的幽靈按鈕,圖片可以通過枚舉類型設置圖片在按鈕標題的上左下右,支持設置圖片和標題的間隔,具體代碼如下:
self.ghostButton3 = [[QMUIGhostButton alloc] initWithGhostType:QMUIGhostButtonColorGreen];
self.ghostButton3.titleLabel.font = UIFontMake(14);
[self.ghostButton3 setTitle:@"點擊修改ghostColor" forState:UIControlStateNormal];
[self.ghostButton3 setImage:UIImageMake(@"icon_emotion") forState:UIControlStateNormal];
self.ghostButton3.imageEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0); //設置圖片和標題的間隔
self.ghostButton3.imagePosition = QMUIButtonImagePositionRight; //默認為QMUIButtonImagePositionLeft
self.ghostButton3.adjustsImageWithGhostColor = YES;
[self.ghostButton3 addTarget:self action:@selector(handleGhostButtonColorEvent) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.ghostButton3];
效果如下:
帶圖片的幽靈按鈕.png