OC代码:
-(void)showAlertView{
CLNNNativeAlertView *alertView=[[CLNNNativeAlertView alloc] initWithTitle:@"请接受相关协议" message:@"我同意《租赁协议》、《芝麻信用免押金额度协议》、《内啥服务条款》及东家指定的退订规则" cancelButtonTitle:@"取消" confirmTitle:@"我同意"];
NSDictionary *linkDic1 = @{NSForegroundColorAttributeName:MAIN_COLOR,NSFontAttributeName:[UIFont systemFontOfSize:15]};
NSDictionary *linkDic2 = @{NSForegroundColorAttributeName:YELLOW_COLOR,NSFontAttributeName:[UIFont systemFontOfSize:15]};
NSLog(@"%@%@",linkDic1,linkDic2);
__weak typeof(self) weakSelf=self;
CJLabelConfigure *configure = [CJLabel configureAttributes:linkDic1 isLink:YES activeLinkAttributes:linkDic2 parameter:WEB_rent clickLinkBlock:^(CJLabelLinkModel *linkModel) {
BrowserViewController *vc=[[BrowserViewController alloc] init];
vc.loadMethod=linkModel.parameter;[weakSelf.navigationController pushViewController:vc animated:YES];
} longPressBlock:nil];
[configure setActiveLinkAttributes:linkDic1];
alertView.messageLabel.text = [CJLabel configureAttrString:alertView.messageLabel.attributedText withString:@"《租赁协议》" sameStringEnable:YES configure:configure];
CJLabelConfigure *configure1 = [CJLabel configureAttributes:linkDic1 isLink:YES activeLinkAttributes:linkDic2 parameter:WEB_zhima clickLinkBlock:^(CJLabelLinkModel *linkModel) {
BrowserViewController *vc=[[BrowserViewController alloc] init];
vc.loadMethod=linkModel.parameter;
[weakSelf.navigationController pushViewController:vc animated:YES];
} longPressBlock:nil];
alertView.messageLabel.text = [CJLabel configureAttrString:alertView.messageLabel.attributedText withString:@"《芝麻信用免押金额度协议》" sameStringEnable:YES configure:configure1];
CJLabelConfigure *configure2 = [CJLabel configureAttributes:linkDic1 isLink:YES activeLinkAttributes:linkDic2 parameter:WEB_terms clickLinkBlock:^(CJLabelLinkModel *linkModel) {
BrowserViewController *vc=[[BrowserViewController alloc] init];
vc.loadMethod=linkModel.parameter;
[weakSelf.navigationController pushViewController:vc animated:YES];
} longPressBlock:nil];
alertView.messageLabel.text = [CJLabel configureAttrString:alertView.messageLabel.attributedText withString:@"《内啥服务条款》" sameStringEnable:YES configure:configure2];
alertView.confirmButtonAction=^(){
[weakSelf continuePay];
};
alertView.cancelButtonAction=^(){
};
[alertView showAlert];
}
JS代码:
require('CLNNNativeAlertView, UIColor, UIFont, BrowserViewController, CJLabel');
defineClass('NewPayController', {
showAlertView: function() {
var alertView=CLNNNativeAlertView.alloc().initWithTitle_message_cancelButtonTitle_confirmTitle("请接受相关协议", "我同意《租赁协议》、《芝麻信用免押金额度协议》、《内啥服务条款》及东家指定的退订规则", "取消", "我同意") ;
var linkDic1 = {
"NSColor":UIColor.colorWithHexString("0097F9"),
"NSFont":UIFont.systemFontOfSize(15)
};
var linkDic2 = {
"NSColor":UIColor.colorWithHexString("ffbb07"),
"NSFont":UIFont.systemFontOfSize(15)
};
var weakSelf = self;
var configure = CJLabel.configureAttributes_isLink_activeLinkAttributes_parameter_clickLinkBlock_longPressBlock(linkDic1, 1, linkDic2, "API", block("void, CJLabelLinkModel*", function(linkModel) { var vc=BrowserViewController.alloc().init() ;
vc.setLoadMethod(linkModel.parameter());
weakSelf.navigationController().pushViewController_animated(vc, 1) ;
}), null) ;
alertView.messageLabel().setText(CJLabel.configureAttrString_withString_sameStringEnable_configure(alertView.messageLabel().attributedText(), "《租赁协议》", 1, configure));
var configure1 = CJLabel.configureAttributes_isLink_activeLinkAttributes_parameter_clickLinkBlock_longPressBlock(linkDic1, 1, linkDic2, "API", block("void, CJLabelLinkModel*", function(linkModel) { var vc=BrowserViewController.alloc().init() ;
vc.setLoadMethod(linkModel.parameter());
weakSelf.navigationController().pushViewController_animated(vc, 1) ;
}), null) ;
alertView.messageLabel().setText(CJLabel.configureAttrString_withString_sameStringEnable_configure(alertView.messageLabel().attributedText(), "《芝麻信用免押金额度协议》", 1, configure1) );
var configure2 = CJLabel.configureAttributes_isLink_activeLinkAttributes_parameter_clickLinkBlock_longPressBlock(linkDic1, 1, linkDic2, "API", block("void, CJLabelLinkModel*", function(linkModel) {
var vc=BrowserViewController.alloc().init() ;
vc.setLoadMethod(linkModel.parameter());
weakSelf.navigationController().pushViewController_animated(vc, 1) ;
}), null) ;
alertView.messageLabel().setText(CJLabel.configureAttrString_withString_sameStringEnable_configure(alertView.messageLabel().attributedText(), "《内啥服务条款》", 1, configure2) );
alertView.setConfirmButtonAction(block("void, ", function() {
weakSelf.continuePay() ;
}));
alertView.setCancelButtonAction(block("void, ", function() {
}));
alertView.showAlert() ;
}}, {});
总结:NSForegroundColorAttributeName 在js中要写成"NSColor"。
获取方法为用NSLog打印,如NSFontAttribute打印出来是NSFont,则在js中写成"NSFont",注意要加双引号。