如何添加自定義控件
基于一鍵登錄的拉起授權頁面功能,如果想要在我們的授權頁面中添加自定義組件,例如使用其他方式登錄的按鈕,來實現其他方式登錄功能,為用戶呈現更多選擇登錄的方式。本文介紹如何在一鍵登錄授權界面中實現添加自定義控件功能,實現方式如下:
//自定義授權頁面
-(void)setupAuthPageCustomStyle:(UIViewController *)authVC userInfo:(SVSDKHyProtocolUserInfo *)userInfo
{//授權頁viewUIView * authPageView = authVC.view;//中間可以對原有授權頁上的按鈕文字等作自定義操作```//***添加自定義控件****// 自定義返回按鈕UIButton *customBackButton = [UIButton buttonWithType:UIButtonTypeCustom];[customBackButton setImage:[UIImage imageNamed:@"fh"] forState:UIControlStateNormal];[customBackButton setTitle:@"返回" forState:UIControlStateNormal];[customBackButton setTitleColor:[UIColor colorWithRed:35/255.0 green:35/255.0 blue:38/255.0 alpha:1/1.0] forState:UIControlStateNormal];customBackButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];[customBackButton addTarget:self.target action:@selector(customBackAction:) forControlEvents:UIControlEventTouchUpInside];[authPageView addSubview:customBackButton];UIView *bottomView = [[UIView alloc] init];[authPageView addSubview:bottomView];UILabel *mLbl = [[UILabel alloc] init];mLbl.textAlignment = NSTextAlignmentCenter;mLbl.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13];mLbl.textColor = [UIColor colorWithRed:184/255.0 green:184/255.0 blue:188/255.0 alpha:1/1.0];mLbl.text = @"其他方式登錄";[mLbl sizeToFit];[bottomView addSubview:mLbl];UIButton *wxBtn = [[UIButton alloc] init];[wxBtn setBackgroundImage:[UIImage imageNamed:@"wc"] forState:UIControlStateNormal];[wxBtn addTarget:self.target action:@selector(weixinLoginAction:) forControlEvents:UIControlEventTouchUpInside];[bottomView addSubview:wxBtn];UIButton *zhBtn = [[UIButton alloc] init];[zhBtn setBackgroundImage:[UIImage imageNamed:@"zh"] forState:UIControlStateNormal];[zhBtn addTarget:self.target action:@selector(usernameLoginAction:) forControlEvents:UIControlEventTouchUpInside];[bottomView addSubview:zhBtn];//布局(可以進行豎屏和橫屏的布局):自定義控件和授權頁基本控件可以放一起統一布局即可```//自定義控件布局(這里使用的是第三方布局控件Masonry)[customBackButton mas_remakeConstraints:^(MASConstraintMaker *make) {make.width.height.mas_equalTo(50);make.left.mas_equalTo(15);make.top.mas_equalTo(15);}];// bottomView[bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {make.bottom.mas_equalTo(privacyTextView.mas_top);make.centerX.mas_equalTo(0);make.width.mas_equalTo(SVD_ScreenWidth);make.height.mas_equalTo(70+mLbl.bounds.size.height);}];[mLbl mas_remakeConstraints:^(MASConstraintMaker *make) {make.bottom.mas_equalTo(wxBtn.mas_top).offset(-10);make.centerX.mas_equalTo(0);}];[wxBtn mas_remakeConstraints:^(MASConstraintMaker *make) {make.bottom.mas_equalTo(-10);make.centerX.mas_equalTo(-50);make.width.height.mas_equalTo(48);}];[zhBtn mas_remakeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(wxBtn);make.centerX.mas_equalTo(50);make.width.height.mas_equalTo(48);}];}