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. JPEG/PNG/GIF图片格式简析

    JPEG/PNG/GIF是Web浏览器广泛支持的3种图片格式. 1.JPEG格式最适合保存照片和其他复杂图像. 2.GIF和PNG格式最适合保存logo和其他包含单色.线条.文本的简单图形. 3.JP ...

  2. JavaScript 事件处理机制

    DOM 事件流 DOM 是一个树型结构,当一个HTML元素产生一个事件时,该事件会在该元素结点与根节点之间按特定的顺序传播,路径所经过的节点都会收到该事件,这个传播过程可称为DOM事件流.而事件传播的 ...

  3. PDO添加数据的预处理语句

    1.添加页面<h1>添加数据</h1><form action="chuli.php" method="post"> < ...

  4. MediaPlayer音乐播放器、上一首、下一首、播放、停止、自动下一首、进度条

    本文介绍MediaPlayer的使用.MediaPlayer可以播放音频和视频,另外也可以通过VideoView来播放视频,虽然VideoView比MediaPlayer简单易用,但定制性不如用Med ...

  5. Android 限定符

    Android中一些常见的限定符可以参考下表. 使用最小宽度限定符 在上一小节中我们使用large限定符成功解决了单页双页的判断问题,不过很快又有一个新的问题出现了,large到底是指多大呢?有的时候 ...

  6. SQL Server存储过程输入参数使用表值

    转载自:http://blog.csdn.net/smithliu328/article/details/9996149 在2008之前如果我们想要将表作为输入参数传递给SQL Server存储过程使 ...

  7. Asp.Net MVC 模型(使用Entity Framework创建模型类)

    这篇教程的目的是解释在创建ASP.NET MVC应用程序时,如何使用Microsoft Entity Framework来创建数据访问类.这篇教程假设你事先对Microsoft Entity Fram ...

  8. linux内核完全剖析——基于0.12内核-笔记(2)-统一编址和独立编址

    IO是什么 ? IO(Input and Output)是输入输出接口.是CPU和其他外部设备(如串口.LCD.触摸屏.LED等)之间通信的接口.一般的,我们说的IO就是指CPU的各种内部或外部外设. ...

  9. python的学习之路day2

    1.什么是常量: 常量在程序中是不变的量 但是在python中所有的变量都可以改 注意:为了防止区分错误,所以python中常量使用大写命名 例如: MYSQL_CONNECTION = '192.1 ...

  10. c语言:复合文字

    复合文字的意义,相当于是在C语言中,为数组类型定义了一种类似于8之于int,'w'之于char一样的常量类型,所以从C99之后,可以在一些地方使用复合文字来代替数组使用. 复合文字的声明 (]){,, ...