pushViewController(viewController, animated:true) } 3、AppDelegate.swift中的didFinishLaunchingWithOptions...rootViewController =navigationController return true } 4、SecondSubViewController.swift import UIKit...40)) push.setTitle(“Push Page”, for:UIControlState()) push.backgroundColor = UIColor.orange push.addTarget...root.setTitle(“Goto Root Page”, for:UIControlState()) root.backgroundColor = UIColor.orange root.addTarget...popToRootViewControllerAnimated(animated:true) } 6、更改导航栏的可见性/导航栏样式修改:FirstSubViewController.swift中的viewWillAppear
//MARK:重写方法 override func viewDidLoad() { super.viewDidLoad() tabBar.addSubview...= CGPoint(x: tabBar.center.x, y:tabBar.bounds.height * 0.5) //方法1:Selector("方法名") Swift...已经不推荐使用,会被提示改成第二种代替 // composeBtn.addTarget(self, action:Selector(("composeBtnClick")), for: ....touchUpInside) //方法2:Selector("类名.方法名") 推荐写法 composeBtn.addTarget(self, action:#selector...MainViewController.composeBtnClick), for: .touchUpInside) //方法3:"方法名" // composeBtn.addTarget
前几天逛Github,偶然看到一个Swift的项目 —— 30DaysOfSwift,作者一共用30个小项目,来熟悉Swift语言,而我正好也学习了一段时间的Swift语言,准备仿照这样的模式,来更加深入的了解...UI部分 今天做的是一个计时器项目 作者在这个项目中,使用AutoLayout来完成自动布局,使用StoryBoard完成UI创建。...而我一直都是喜欢用纯代码布局,UI的搭建也是使用代码完成。所以我在写这个小Demo之前在我的项目里集成了SnapKit,使用类似Objective-C中常用的masonry框架来完成自动布局。...这里我还发现一个Swift中的小问题,使用cocoadPods集成第三方库,引用不到头文件的解决方法和Objective-C不一样。...= UIFont.systemFontOfSize(15) button.backgroundColor = UIColor.clearColor() button.addTarget
1、 ViewController.swift #视图控制器 更改类的视图控制器 ?...button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget...(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button...height:44)) button.setTitle(“关闭”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget...(self, action:#selector(NewViewController.dismissSelf),for:.touchUpInside) self.view.addSubview(button
6EDD4AC9-47E3-401F-91A4-2DA836439787.png Demo开始之前,我们想想应该会使用到屏幕宽高等一些常用的值,在OC中,咱们可以使用PCH然后宏定义,然而在Swift中...(loginBtn) loginBtn.addTarget(self, action: "loginAction", forControlEvents: .TouchUpInside)...textColor = UIColor.whiteColor() backBtn.addTarget(self, action: "back", forControlEvents: .TouchUpInside...学了这么几天,我发现Swift还是比较容易入手的,下篇文章我会用一个小的项目,本人是做室内地图SDK的,这次的小项目是仿我OC写的SDK Demo,使用Swift和OC混编,集成百度地图SDK和自己的室内...在下篇文章中会讲讲,Swift项目已上github:https://github.com/qingmomo/Swift-die OC版的demo在我们官网:http://www.innsmap.com
最近在学iOS开发,本系列会针对iOS从前到后的开发进行全面讲解,小到开发工具使用,大到应用市场上线。 ?...2.3.2 添加一个按钮,并添加按钮点击事件的监听方法 // 2.创建一个按钮 let btn = UIButton(type: .contactAdd) // 2.1 添加到当前视图 v.addSubview...(btn) // 2.2 添加点击事件 btn.addTarget(self, action: #selector(btnClick), for: .touchUpInside) // 2.3 btnClick...== alloc / init 等价 3.2 类方法类比 Swift: UIColor.yellow OC: [UIColor yellow] 3.3 访问当前对象的属性类比 建议:都不使用self...,不需要使用`:` OC: @selector 3.7 调试对比 Swift: print(xxx) 效率高,log中不包含时间,用#function来打印当前执行的方法 OC: NSLog,用__FUNCTION
: .normal) 4uiButton.translatesAutoresizingMaskIntoConstraints = false 5uiButton.addTarget(self, action...: #selector(click), for: .touchUpInside) 6 7view.addSubview(uiButton) 8 9uiButton.snp.makeConstraints...{ make in 10 make.center.equalTo(view) 11} COPY 方便起见,以上代码使用了 SnapKit,在运行之前请先下载安装 SnapKit 在再底下加个方法...UIView 5 6view.addSubview(sview) 7sview.snp.makeConstraints({ make in 8 make.bottom.equalTo(view)...,同时还能使用 UINavigationController 更完善的方法。
创建CustomizeUITableViewCell.swift import UIKit class CustomizeUITableViewCell:UITableViewCell { var...self.detail.setTitle(“详情”, for:UIControlState()) self.detail.backgroundColor = UIColor.gray self.detail.addTarget...(self, action:“showDetail:”,for:UIControlEvents.touchUpInside) self.addSubview(self.thumbnail) self.addSubview...(self.title) self.addSubview(self.detail) } func showDetail(_ sender:UIButton){ print(“显示详细信息”)
//设置视图的背景颜色 redV.backgroundColor = UIColor.red; //添加到当前页面 view.addSubview...redV.center = view.center; let btn = UIButton(type: .contactAdd); redV .addSubview...(btn); btn.addTarget(self, action: #selector(btnClicked), for: .touchUpInside);...} @objc func btnClicked()->String{ print(#function); return "111"; } } swift...imageview let img = UIImageView(frame: CGRect(x: 100, y: 300, width: 50, height: 50)) view .addSubview
1、创建三个视图控制器 FirstViewController、SecondViewController、ThirdViewController 2、在FirstViewController.swift...label.textAlignment = NSTextAlignment.center label.font = UIFont(name:“Arial”, size:36) self.view.addSubview...(label) 3 AppDelegate.swift的didFinishLaunchingWithOptions方法: let firstViewController = FirstViewController...button.setTitle(“进入第二页”, for:UIControlState()) 3 button.backgroundColor = UIColor.black 4 button.addTarget...(self, action: selector(FirstViewController.enterPage2), for:.touchUpInside) 5 self.view.addSubview(
" Swift 基本语法05-"String" Swift 基本语法06-数组和字典 Swift 简介 Swift2014年06月WWDC大会发布 2015年底开源 IBM开始用Swift做后台开发...Button 的创建 // 创建按钮 let btn = UIButton(type: .contactAdd) view.addSubview(btn) btn.center = view.center...btn.addTarget(self, action: #selector(clickMe), for: .touchUpInside) // 按钮的点击事件 func clickMe(btn:UIButton...UIColor.red // 颜色选择器直接设置 v.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 0, alpha: 1) view.addSubview...imageView.image = UIImage(named: "user") imageView.image = #imageLiteral(resourceName: "user") view.addSubview
使用UIWebView加载本地数据或资源有如下三种方式: 1,使用 **loadHTMLString **方法加载HTML内容 2,使用 **loadRequest **方法加载本地资源(也可用于加载服务器资源...) 3,先将内容保存成 **Data **数据,再使用 **load **方法加载 使用样例 通过 **UISegmentedControl **分别控制网页控件 "网页HTML",“显示HTML...:self.view.frame.size.width - 100, height:40) segmented.selectedSegmentIndex = 1 segmented .addTarget...(self, action: #selector(segmentedAction), for: .valueChanged) self.view.addSubview(segmented...else if segmented.selectedSegmentIndex == 2 { let path = Bundle.main.path(forResource: "Swift
本文就介绍如何自定义alertView,看完你就懂得制作属于自己的alertView了 一、创建DWAlert.swift 创建一个类名为在DWAlert.swift,在class DWAlert:...UIFont.systemFont(ofSize: 14.0) self.button.setTitleColor(UIColor.white, for: .normal) self.button.addTarget...(cancleBtn) cancleBtn.addTarget(self, action: #selector(dismissAlert), for: .touchUpInside) } 因为调用...self.init(),所以得使用关键字convenence,使上述函数变成便利构造函数,具体看convenence介绍 三、alertView的显示与隐藏 1、show实现alertView显示...五、使用DWAlert 在ViewController创建一个按钮,并添加一个点击事件ClickMe,在方法里面创建alertView @IBAction func ClickMe(_ sender:
效果如图: 代码如下: // // ViewController.swift // TwoSidedView // // Created by mayl on 2017/12/14. // Copyright...super.viewDidLoad() setUpUI() } func setUpUI() { view.addSubview...(gBtn) gBtn.addTarget(self, action: #selector(ViewController.btnDidClick), for: UIControlEvents.touchUpInside...) gBtn.center = view.center gBtn.addSubview(gImgV4BottomSide) gBtn.layer.transform...= CATransform3DMakeRotation(CGFloat(Double.pi), 0, 1, 0) gBtn.addSubview(gImgV4TopSide
介绍 Swift 可以利用 OC 的 runtime 和 KVC ,在运行时向一个对象添加值存储,这种方式称之为Associated Object。...在使用 extension 扩展现有类的功能时,使用Associated Object的方式,可以将一个值 “关联” 到已有的要扩展的类上。该知识点在 iOS 开发中使用往往能优雅地解决很多问题。...,并且通过 & 操作符取地址并作为 UnsafeRawPointer 类型被传入,这在 Swift 与 C 协作和指针操作时是一种很常见的用法。...objc_setAssociatedObject(btn, &AssociateKeys.key, params[i], .OBJC_ASSOCIATION_COPY) btn.addTarget...(self, action: #selector(itemClick(button:)), for:.touchUpInside) self.view.addSubview(btn
Swift 接着就是源码了 1....(thumbnailView) contentView.addSubview(titleLabel) contentView.addSubview(subtitleLabel)...= CustomPlayerCircularButtonView(symbolName: "pip.enter", height: buttonSideLength) startButton.addTarget...= CustomPlayerCircularButtonView(symbolName: "pip.exit", height: buttonSideLength) stopButton.addTarget...CustomPlayerCircularButtonView(symbolName: "xmark", height: buttonSideLength) closePlayerButton.addTarget
前言 总结下 swift下的基础语法,里面涉及到:常量&变量、Swift中的数据类型、逻辑分支、循环、字符串相关、数组和字典、方法的书写调用等内容,考虑到阅读体验分多篇来展示,希望对大家学习swift...Swift| 基础语法(一) Swift| 基础语法(二) Swift| 基础语法(三) Swift| 基础语法(四) Swift| 基础语法(五) 本文涉及: 纯代码创建应用根试图 UILabel...(sc) sc.addSubview(mylabel) sc.addSubview(but) sc.addSubview(imageV) // 按钮的点击事件...} 在Swift中,创建tableViewCell的方法可以分为两种创建tableView时候注册和需要使用时手动创建。先聊聊创建tableView的时候直接注册cell: myTb?....UITabBarController() tabbarController.tabBar.barTintColor = UIColor.white // 注意:视图控制器超过5个时(不包含
1,关于编译时和运行时 编译时: Objective-C、Java、Swift等高级语言,其可读性很强,但是并不能直接被机器识别,所以就需要将这些源代码编译成相对应的机器语言(比如汇编语言),最终会生成二进制代码...实际上,当你真正理解了Runtime之后,你会发现:“原来我真的可以用Runtime解决很多实际问题~” (1)Runtime——使用类目给某个类添加属性 (2)通过消息转发防止程序崩溃:Runtime...一般情况下,如果我们需要在某页面进行页面跳转到另外一个页面,那么就在当前页面使用import引入另一页面的文件,然后新建跳转即可。...@"class":@"NormanGreenVC", @"data":@{ @"slogan":@"和谐学习,不急不躁...forState:UIControlStateNormal]; [greenBtn setBackgroundColor:UIColor.greenColor]; [greenBtn addTarget
在Swift的学习过程中,个人感觉虽说两种语言的相似度很大,但是Swift依然在代码风格上有着和OC很大的差异。...在总结了一些基本的用法之后,我尝试使用Swift自定义UITabBarController和UITabbar,开启这Siwft项目的关键一步,首先展示一下效果图: ?...屏幕快照 2017-07-15 下午2.40.54.png 第一步:创建Swift工程# 1.使用Xcode创建一个Swift初始项目ZSTestSwift,效果如下: ?...String for i in 0...controllerNameArray.count-1 { //动态获取的命名空间是不包含.的, 所以需要我们自己手动拼接...rootViewController = MainTabBarController(); return true } 总结:以上就是在OC代码的基础上,使用Swift来自定义标签控制器的方法和步骤
Swift-Button的常用 func setButton() { // 创建一个类型为contactAdd的按钮 let button:UIButton = UIButton(type...(self, action: #selector(buttonAction), for:.touchUpInside) button .addTarget(self, action: #selector...(action2(button:)), for:.touchUpInside) self.view.addSubview(button) } func buttonAction() {...TouchUpInside:在控件之内触摸并抬起事件 TouchUpOutside:在控件之外触摸抬起事件 TouchCancel:触摸取消事件,即一次触摸因为放上太多手指而被取消,或者电话打断 */ Swift...里Label的使用 func setLabel() { let label = UILabel(frame:CGRect(x:50, y:300, width:200, height:30))