博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift与OC代码转换实例
阅读量:5033 次
发布时间:2019-06-12

本文共 3547 字,大约阅读时间需要 11 分钟。

1.

Objectice-C code:

1 NSShadow *shadow = [NSShadow new]; 2  3 [shadow setShadowColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]]; 4  5 [shadow setShadowOffset:CGSizeMake(0, 1)]; 6  7 NSDictionary *attributes = @{ 8  9                                 NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],10 11                                 NSShadowAttributeName: shadow,12 13                                 NSFontAttributeName: [UIFont fontWithName:@"AmericanTypewriter" size:16.0]14 15                              };16 17 [self.navigationItem.rightBarButtonItem setTitleTextAttributes:attributes forState: UIControlStateNormal];18 19 // Or you can use.20 21 [[UIBarItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];

Swift Code:

// Bar title text colorlet shadow = NSShadow()shadow.shadowColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)shadow.shadowOffset = CGSizeMake(0, 1)let color : UIColor = UIColor(red: 220.0/255.0, green: 104.0/255.0, blue: 1.0/255.0, alpha: 1.0)let titleFont : UIFont = UIFont(name: "AmericanTypewriter", size: 16.0)!let attributes = [                        NSForegroundColorAttributeName : color,                        NSShadowAttributeName : shadow,                        NSFontAttributeName : titleFont                 ]self.navigationItem.rightBarButtonItem?.setTitleTextAttributes(attributes, forState: UIControlState.Normal)// Or you can useUIBarItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal)

 2.

OC:

    //设置导航栏字体颜色

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];

    //[UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont

Swift:

UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(),

        NSFontAttributeName: UIFont(name: "Heiti SC", size: 24.0)!]

3.

OC: 

//改变UITabBarItem字体颜色

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0 green:0.72 blue:0.69 alpha:1],UITextAttributeTextColor, nil] forState:UIControlStateSelected];

Swift:

let attributes =  [NSForegroundColorAttributeName: UIColor(red: 0, green: 0.72, blue: 0.69, alpha: 1)]

        UITabBarItem.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Selected)

4.

OC:

//警示样式

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是个UIAlertController的默认样式" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];

    [alertController addAction:cancelAction];

    [alertController addAction:okAction];

    [self presentViewController:alertController animated:YES completion:nil];

Swift:

//警示样式

        let alertController = UIAlertController(title: "标题", message:"这个是UIAlertController的默认样式", preferredStyle: UIAlertControllerStyle.Alert)

        let cancelAction = UIAlertAction(title: "取消", style:UIAlertActionStyle.Destructive, handler: nil)

        let okAction = UIAlertAction(title: "确定", style:UIAlertActionStyle.Default, handler:nil)

        alertController.addAction(cancelAction)

        alertController.addAction(okAction)

        self.presentViewController(alertController,animated:true,completion:nil)

 

转载于:https://www.cnblogs.com/abelsu/p/4858443.html

你可能感兴趣的文章
读代码
查看>>
pythonweb框架Flask学习笔记02-一个简单的小程序
查看>>
火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法
查看>>
NSThread创建方式
查看>>
Hadoop+Spark+Hbase部署整合篇
查看>>
Android基础类之BaseAdapter
查看>>
Pagerank
查看>>
电脑重装系统按什么键进U盘PE
查看>>
MyEclipse2014安装图解
查看>>
Gym 100733C
查看>>
如果你觉得我的博客对你有帮助,请帮忙加点我所在团队博客访问量http://home.cnblogs.com/u/newbe/...
查看>>
gulp基本用法
查看>>
codeforces 540E"Infinite Inversions"
查看>>
vivado烧写bin文件到flash 中
查看>>
verilog 条件编译命令`ifdef、`else、`endif 的应用
查看>>
Scala设计模式
查看>>
Android实践项目汇报总结(下)
查看>>
char[] 转换为LPWSTR
查看>>
datatable.rows.indexof(dr)返回的是啥?
查看>>
RabbitMq笔记()
查看>>