title: ios杂记
date: 2015-12-20 #写作时间
description: 逗指导的IOS笔记
categories: #文章分类
- ios
tags: #文章标签
- OC
- swift
- 杂记
- ios
toc: true # 生成目录
author: Creep
comments:
original:
permalink: #指定链接
---
# ios 针对状态栏操作
## 在ViewController中操作当前ViewController的状态栏
```swift
/**
隐藏状态栏
*/
override func prefersStatusBarHidden() -> Bool {
return true;
}
/**
设置状态栏风格
*/
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent;
}
```
## 在AppDelegate中设置状态栏
```swift
func setupWithStatusBar(application: UIApplication) {
// 设置状态栏隐藏
application.statusBarHidden = true;
application.setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Fade);
// 设置状态栏高亮
application.statusBarStyle = UIStatusBarStyle.LightContent;
application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true);
}
```
## 通过plist文件配置状态栏属性
在**plist**里增加一行 **UIStatusBarStyle**(或者是“**Status bar style**”也可以),这里可以设置两个值,就是上面提到那两个
`UIStatusBarStyleDefault` 和 `UIStatusBarStyleLightContent`
这样在app启动的launch页显示的时候,statusBar的样式就是上面plist设置的风格。
# Swift - 文本输入框(UITextField)的用法
http://www.hangge.com/blog/cache/detail_530.html
# button 动画
====
http://www.cocoachina.com/industry/20140812/9360.html
# iOS实现渐变背景色的三种方法
====
为了定义渐变色, 至少有四个属性需要定义
```objectivec
@property (nonatomic) CGPoint inputPoint0;
@property (nonatomic) CGPoint inputPoint1;
@property (nonatomic) UIColor *inputColor0;
@property (nonatomic) UIColor *inputColor1;
```
两个 CGPoint 属性定义了渐变色开始和结束的地方。 They are defined in a unit coordinate space where (0, 0) at the top left and (1, 1) at the bottom right. The two UIColor properties define the start colour and the end colour.
## CAGradientLayer
We are not going to discuss the details of how to use CAGradientLayer. There is a good article talking about it: http://www.cnblogs.com/YouXianMing/p/3793913.html.
```objectivec
CAGradientLayer *layer = [CAGradientLayer new];
layer.colors = @[(__bridge id)_inputColor0.CGColor, (__bridge id)_inputColor1.CGColor];
layer.startPoint = _inputPoint0;
layer.endPoint = _inputPoint1;
layer.frame = self.bounds;
[self.layeraddSublayer:layer];
```
## CGGradientRef
About Core Graphics and Core Image, please refer here, a very very good article:
http://www.techotopia.com/index.php/An_iOS_7_Graphics_Tutorial_using_Core_Graphics_and_Core_Image
Note that CAGradientLayer is using unit coordinate space while Core Graphics and Core Image are not. More Interestingly, Core Graphics’ coordinate space where (0, 0) starts at the top left is different from Core Image’s where (0, 0) starts at bottom left.
The following code is called in drawRect:.
```objectivec
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = {0,1};
NSArray *colors = @[(__bridge id)_inputColor0.CGColor, (__bridge id)_inputColor1.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef) colors, locations);
CGColorSpaceRelease(colorSpace);
CGPoint startPoint = (CGPoint){rect.size.width * _inputPoint0.x, rect.size.height * _inputPoint0.y};
CGPoint endPoint = (CGPoint){rect.size.width * _inputPoint1.x, rect.size.height * _inputPoint1.y};
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGGradientRelease(gradient);
UIGraphicsPopContext();
```
## Core Image
The following code is called in drawRect:.
```objectivec
CIFilter *ciFilter = [CIFilter filterWithName:@"CILinearGradient"];
CIVector *vector0 = [CIVector vectorWithX:rect.size.width * _inputPoint0.x Y:rect.size.height * (1 - _inputPoint0.y)];
CIVector *vector1 = [CIVector vectorWithX:rect.size.width * _inputPoint1.x Y:rect.size.height * (1 - _inputPoint1.y)];
[ciFilter setValue:vector0 forKey:@"inputPoint0"];
[ciFilter setValue:vector1 forKey:@"inputPoint1"];
[ciFilter setValue:[CIColor colorWithCGColor:_inputColor0.CGColor] forKey:@"inputColor0"];
[ciFilter setValue:[CIColor colorWithCGColor:_inputColor1.CGColor] forKey:@"inputColor1"];
CIImage *ciImage = ciFilter.outputImage;
CIContext *con = [CIContext contextWithOptions:nil];
CGImageRef resultCGImage = [con createCGImage:ciImage
fromRect:rect];
UIImage *resultUIImage = [UIImage imageWithCGImage:resultCGImage];
CGImageRelease(resultCGImage);
[resultUIImage drawInRect:rect];
```
Sample code can be found here: https://github.com/RungeZhai/LGGradientBackgroundView
# mac系统如何显示和隐藏文件
====
## Mac OS X操作系统下
隐藏文件是否显示有很多种设置方法,最简单的要算在`Mac终端`输入命令。显示/隐藏Mac隐藏文件命令如下(注意其中的空格并且区分大小写)。
## 显示Mac隐藏文件的命令:
```
defaults write com.apple.finder AppleShowAllFiles -bool true
```
or
```
defaults write com.apple.finder AppleShowAllFiles YES
```
## 隐藏Mac隐藏文件的命令:
```
defaults write com.apple.finder AppleShowAllFiles -bool false
```
or
```
defaults write com.apple.finder AppleShowAllFiles NO
```