说到脚本,大家可能会想到 ruby, js, shell 等等。我们一般用这些脚本对我们的开发进行一些辅助工作。 比如自动打包,更新数据等等。合理的脚本自动化配置,能节省我们很多处理繁杂事务的时间,极大的提高我们的效率。 同样, Swift 也提供了这样的能力,所以下次我们再有类似的需求的时候,就多了一种选择。并且如果你开发项目使用的就是 Swift 的话,那么再用它来写脚本几乎就没有什么
let view = UIView(frame: CGRectMake(10.0, 10.0, 200.0, 200.0))
// 添加到父视图
self.view.addSubview(view)
// 背景颜色
view.backgroundColor = UIColor.redColor() // layer层属性设置
let button = UIButton(type: UIButtonType.Custom) // 添加到父视图,并设置frame
self.view.addSubview(button)
button.frame = CGRectMake(10.0, 10.0, 200.0, 40.0) // 背景属性设置
button.backgroundColor = UIColor.yellowCol
let imageview = UIImageView(frame: CGRectMake(10.0, 10.0, 100.0, 100.0))
self.view.addSubview(imageview)
imageview.backgroundColor = UIColor.yellowColor()
imageview.image = UIImage(named: "no
let textfield = UITextField(frame: CGRectMake(10.0, 10.0, 200.0,40.0))
self.view.addSubview(textfield) // 字体属性设置
textfield.textColor = UIColor.blackColor()
textfield.font = UIFont(name: "GillSans", si
let textview = UITextView(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.view.bounds) - 10.0 * 2), 80.0))
self.view.addSubview(textview)
textview.backgroundColor = UIColor.lightGrayColor(
https://github.com/potato512/SYSwiftLearning 示例代码如下: 1、参数定义 let width:CGFloat = (UIScreen.mainScreen().bounds.size.width / 3.0)
var label:UILabel?
var addressArray:Array<AnyObject>?
var cityArray:Arra
https://github.com/potato512/SYSwiftLearning 效果图 示例代码 // 实例化UIDatePicker(默认宽高分别是:屏幕的宽度,216的高度)
let datepicker = UIDatePicker()
self.view.addSubview(datepicker)
// 属性设置
datepicker.backgroundCo
let slider = UISlider(frame: CGRectMake(10.0,10.0, (CGRectGetWidth(self.view.bounds) - 10.0 * 2), 20.0))
self.view.addSubview(slider)
slider.backgroundColor = UIColor.lightGrayColor() // 设置值(默认值为0.0,且
// 实例化
let searchbar = UISearchBar(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.view.frame) - 10.0 * 2), 40.0))
self.view.addSubview(searchbar)
searchbar.backgroundColor = UIColor.yello
// 实例化(注意:默认宽高是 51 x 31。指定大小无效)
let switchview = UISwitch(frame: CGRectMake(10.0, 10.0, 0.0, 0.0))
self.view.addSubview(switchview)
switchview.backgroundColor = UIColor.yellowColor()
// 打开时背景
默认高度是2.0。自定义高度无效,可通过transform属性设置高度 // 实例化(默认高度是2.0。自定义高度无效,可通过transform属性设置高度)
let progressview = UIProgressView(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.view.bounds) - 10.0 * 2), 10.0))
se
// 实例化
let activityview = UIActivityIndicatorView(frame: CGRectMake(10.0, 10.0, 50.0, 50.0))
self.view.addSubview(activityview)
activityview.backgroundColor = UIColor.yellowColor()
ac
let segment = UISegmentedControl(frame: CGRectMake(10.0, 10.0, (CGRectGetWidth(self.view.bounds) - 10.0 * 2), 40.0))
self.view.addSubview(segment)
segment.backgroundColor = UIColor.lightGrayC
声明:var activityLoadingView:UIActivityIndicatorView! //显示正在加载的控件 //初始化方式一 activityLoadingView = UIActivityIndicatorView(frame: CGRectMake(self.view.frame.size.width/2-25,self.v
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UIViewController视图控制器在iOS研发中不可或缺,基本上每一个页都的研发都会使用到。 在使用过程中,主要使用了以下几个方面。 1、视图控制器的属性设置。如背景颜色,适配,视图控制器数组属性等 2、视图控制器的生命周期的控制 3、视图控制器间的转场present,或push,以及相对应的dismiss,或pop …… // MARK: - 适配
func autoSize()
{
// 导航视图控制器标题
self.navigationItem.title = "navigationController"
// 导航视图控制器样式
self.navigationController!.setNavigationStyleDefault()
// 导航视图控制器左按钮
self.navigationItem.leftBarButtonIte
源码:https://github.com/potato512/SYSwiftLearning swift开发定义某个类的扩展类时,使用关键字extension。 extension SomeType {
// 加到SomeType的新功能写到这里
}
// 一个扩展可以扩展一个已有类型,使其能够适配一个或多个协议,语法格式如下:
extension SomeType: SomeProto
源码:https://github.com/potato512/SYSwiftLearning // MARK: - 初始化tableview
func setUI()
{
// 初始化tableView
self.mainTableView = UITableView(frame:self.view.bounds,style:UITableViewSty