Skip to content

Instantly share code, notes, and snippets.

@zhuchaowe
zhuchaowe / iptables屏蔽邮件服务
Created May 24, 2018 02:38
iptables屏蔽邮件服务方法,防止被人利用发送垃圾邮件
```
iptables -A OUTPUT -p tcp --match multiport --dports 25,109,110,143,465,993,995 -m state --state NEW,ESTABLISHED -j REJECT
```
@zhuchaowe
zhuchaowe / WatchKit之数据共享
Created May 24, 2018 02:37
本文将介绍如何使 Watch App 与 iOS App 之间进行数据共享
## App Group
App Group 是一个 App 与其扩展均可以访问的本地文件系统的一块区域。由于 Watch App 与 iOS App 是在不同的沙盒环境下运行,正常情况下他们彼此无法分享数据,因此,我们需要创建一个 App Group,使的它们拥有一个共享的文件区域。
点击项目,在 target 里分别打开项目本身和 Watch App 的 App Groups,点击加号,添加一个 App Group,输入一个唯一的标识符。我们之后会在 Watch App 和 iOS App 中通过该标识符访问同一个 App Group。
![image](http://ww4.sinaimg.cn/large/005yyi5Jjw1emo6uj2xnxj30pe0fmdh7.jpg)
## NSUserDefault
@zhuchaowe
zhuchaowe / iOS开发之指定UIView的某几个角为圆角
Created May 24, 2018 02:36
设置UIView的某几个角为圆角
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用`UIBezierPath`。下面给出一段示例代码。
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];
view2.backgroundColor = [UIColor redColor];
[self.view addSubview:view2];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view2.bounds;
@zhuchaowe
zhuchaowe / IOS8的Encapsulated Height问题
Created May 24, 2018 02:35
设置AutoLayoutCell时遇到的UIView-Encapsulated-Layout-Height
UITableViewCell 设置AutoLayoutCell的时候遇见到`UIView-Encapsulated-Layout-Height(44)`的坑。
看起来像是autolayout在ios8上面的bug,等着苹果啥时候能解决...
后来用@999来解决了= =,实在是无力吐槽了,这里记一笔先,下面是链接。
[这是stackoverflow上面的讨论](http://stackoverflow.com/questions/25059443/what-is-nslayoutconstraint-uiview-encapsulated-layout-height-and-how-should-i)
# 教你如何发布自己的代码到CocoaPods
很多人问起自己的项目如何发布到CocoaPods呢?不少人有这样的疑惑,其实都是没去看官方文档。。
## 注册
CocoaPods 需要0.33版本以上的,用`pod --version`查看,不是0.33的话就更新一下
下一步注册一个账号
```
pod trunk register zhuchao@iosx.me 'zhuchao' --description='macbook pro x72'
@zhuchaowe
zhuchaowe / 三种方式使得iOS应用能够在后台进行数据更新和下载
Created May 24, 2018 02:33
实现iOS应用在后台进行数据更新和下载
## Background Fetch
* 开启
首先在info plist文件中开启UIBackgroundModes的Background fetch。或者手动编辑这个值
```
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
```
@zhuchaowe
zhuchaowe / EasyIOS如何做到提升开发效率
Created May 24, 2018 02:31
EasyIOS框架是以提升开发效率为目标的,基于MVVM架构的快速开发框架,在IOS开发的基础上解决了开发者的以下的痛点。
随着苹果发布了swift语言,很多人拿OC与之对比,下面是苹果列出的Swift几项特性(它们不包含Objective-C已经有的特性,比如自动内存管理)
* 类型推断(Inferred types) – 类型推断让代码更清晰以及更少的错误
* 模块(Modules) – 模块移除了头文件并提供命名空间
* 闭包和函数(Closures & Functions) – 闭包和函数指针相匹配
* 元组(Tuples) – 元组和多重返回值
* 泛型(Generics) – 泛型带来的好处是不言而喻的。
* 结构体(Structs) – 支持方法、扩展、接口的结构体。
* 函数式编程模式(Functional Programming Patterns) – 比如map和filter。
这些都是在Objective-C基础上显而易见的改进。让我们将关于泛型的好处、类型推断、函数式编程等等的争论放到一边,干脆的同意Swift在许多地方比Objective-C要优越。
@zhuchaowe
zhuchaowe / iOS开发之Attributes文字的操作
Created May 24, 2018 02:30
Attributes文字的操作,UITextField框内文字颜色大小等改变。
* 1.`NSKernAttributeName: @10` 调整字句 kerning 字句调整
* 2.`NSFontAttributeName : [UIFont systemFontOfSize:_fontSize]` 设置字体
* 3.`NSForegroundColorAttributeName :[UIColor redColor]` 设置文字颜色
* 4.`NSParagraphStyleAttributeName : paragraph` 设置段落样式
`NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
paragraph.alignment = NSTextAlignmentCenter;`
* 6.`NSBackgroundColorAttributeName: [UIColor blackColor]` 设置背景颜色
* 7.`NSStrokeColorAttributeName: [UIColor blackColor]`设置文字描边颜色,
* 8.`NSStrokeWidthAttributeName: [NSNumber numberWithFloat:2.0f]`设置描边宽度,
@zhuchaowe
zhuchaowe / iOS9应用-NSURLRequest默认协议修改为https
Created May 24, 2018 02:29
iOS9把默认http协议修改为默认https,来督促开发者尽快迁移到https协议上。
今天把现有APP在IOS9上编译了一次发现,所有请求都是timeout
```bash
2015-06-12 10:32:42.087 mcapp[8300:226922] Failed:Error
Domain=NSURLErrorDomain Code=-1001 "The request timed out."
UserInfo=0x7f9b18cdc420 {NSUnderlyingError=0x7f9b18f49e80 "The request timed
out.", NSErrorFailingURLStringKey=https://***.maichong.me/***/share-data?,
NSErrorFailingURLKey=https://***.maichong.me/***/share-data?,
_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102,
NSLocalizedDescription=The request timed out.}
@zhuchaowe
zhuchaowe / golang模板调用函数
Created May 24, 2018 02:27
golang模板开发时如何调用接口函数和自定义函数
## golang 模板调用接口函数
[http://stackoverflow.com/questions/10200178/call-a-method-from-a-go-template](http://stackoverflow.com/questions/10200178/call-a-method-from-a-go-template)
You can even pass parameters to function like follows
```
type Person struct {
Name string
}
func (p *Person) Label(param1 string) string {