1.

Objectice-C code:

 NSShadow *shadow = [NSShadow new];

 [shadow setShadowColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]];

 [shadow setShadowOffset:CGSizeMake(, )];

 NSDictionary *attributes = @{

                                 NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],

                                 NSShadowAttributeName: shadow,

                                 NSFontAttributeName: [UIFont fontWithName:@"AmericanTypewriter" size:16.0]

                              };

 [self.navigationItem.rightBarButtonItem setTitleTextAttributes:attributes forState: UIControlStateNormal];

 // Or you can use.

 [[UIBarItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];

Swift Code:

// Bar title text color

let shadow = NSShadow()

shadow.shadowColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)

shadow.shadowOffset = CGSizeMake(, )

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 use

UIBarItem.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)

Swift与OC代码转换实例的更多相关文章

  1. Swift和Objective-C混合编程——Swift调用OC

    在iOS应用的开发中.Swift必将代替OC,两者的趋势是"短期共存,长期代替".但曾经有太多的代码是用OC语言完毕的,而Swift的开发也从 OC中继承了非常多的特性.两者也是有 ...

  2. Swift与OC区别

    一.Swift与OC区别: 1.swift程序的入口是UIApplicationMain; 2.OC的类是以.h和.m组成的;swift是一.swift结尾的; 3.OC的类是以@interface和 ...

  3. swift与OC之间不得不知道的21点

    swift与OC之间不得不知道的21点   自6月的WWDC大会上由苹果的大神Chris Lattner向我们首次展示swift至今已经大半年时间了,虽然绝大部分软件公司代码里还都见不到一丁点swif ...

  4. Swift与OC混编

    OC调用Swift的方法:添加 import "xxxx-Swift.h" 头文件即可 Swift调用OC的方法:需要建立桥接: xxxx-Bridging-Header.h 头文 ...

  5. iOS开发--Swift 如何完成工程中Swift和OC的混编桥接(Cocoapods同样适用)

    由于SDK现在大部分都是OC版本, 所以假如你是一名主要以Swift语言进行开发的开发者, 就要面临如何让OC和Swift兼容在一个工程中, 如果你没有进行过这样的操作, 会感觉异常的茫然, 不用担心 ...

  6. iOS获取手机型号,类似iphone 7这种 含swift和OC

    获取手机设备信息,如name.model.version等,但如果想获取具体的手机型号,如iphone5.5s这种,就需要如下这种 swift: func phonetype () -> Str ...

  7. swift调用oc语言文件,第三方库文件或者自己创建的oc文件——简书作者

    Swift是怎样调用OC的第三方库的呢?请看下面详情: 情况一: 1.首先打开Xcode,iOS->Application->Single View Application, 选Next. ...

  8. 在项目里交叉使用Swift和OC【转】

    Swift and Objective-C in the Same Project在项目里交叉使用Swift和OC Swift与OC的兼容性使得你可以在项目里使用Swift+OC的方式编写应用程序,称 ...

  9. iOS开发--混编篇&swift与OC混合使用

    Swift与OC混合使用 swift 语言出来后,可能新的项目直接使用swift来开发,但可能在过程中会遇到一些情况,某些已用OC写好的类或封装好的模块,不想再在swift 中再写一次,哪就使用混编. ...

随机推荐

  1. 分布式Session一致性解决方案有哪些?

    1.使用cookie代替session(不安全,不推荐使用) 2.使用数据库存储session(效率低,不推荐使用) 3.使用nginx反向代理ip绑定方法,同一个ip只能在同一台服务器上进行访问(不 ...

  2. DouPHP去除Powered by DouPHP版权的方法

    DouPHP标题版权修改:打开 include 目录下的 action.class.php 文件,搜索“Powered”找到下面一行代码: $page_title = ($titles ? $titl ...

  3. SD从零开始15-18

    SD从零开始15 税(Taxes) 税确定的标准Criteria for tax determination 你可以在sales organization level分配一个rule(blank,A, ...

  4. FineReport连接多维数据库示例及操作

    1. 描述 FineReport连接多维数据库,首先要通过数据连接将多维数据库与FineReport连接起来,然后在数据连接的基础上新建多维数据库XMLA数据集,用于模板设计. 2.XMLA数据连接 ...

  5. JNI使用方法

    JNI可以让我们在java代码中调用本地库的功能. 下面记录一下JNI简单的使用方法 创建java端接口 public class JNIIterface { // 导入最终生成的dll文件 stat ...

  6. Linux —— Vi 命令介绍

    简介 vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器. 这里只是简单地介绍一下它的用法和一小部分指令. 由于对Unix及Linux系统的任何版本,vi编辑 ...

  7. centos安装pip3

    安装pip3 1:安装依赖 yum install openssl-devel -y yum install zlib-devel -y 2:安装setuptools wget --no-check- ...

  8. WebAPI返回时间数据不带T

    最近一段时间项目里面使用WebAPI比较多,但是在返回时间数据的时候回默认带上T,就像这样子 "2016-04-21T13:26:17.4701811+08:00", 这样的数据在 ...

  9. linux下安装jdk安装及环境变量配置

    1.默认是在windows下载,linux下安装 2.在jdk官网下载相应版本的jdk,这次下载为 jdk-8u161-linux-x64.tar.gz 3.将下载好的文件上传到指定目录,我这次把它放 ...

  10. SQL 时间戳转换为日期

    , '1970-01-01 00:00:00') 其中Timestamp为10位的时间戳,+8*3600是获取中国北京时间(东八区)