畅畅的烧烤店

一个程序员的自强不息梦


  • 首页

  • 归档
畅畅的烧烤店

我的2016年,我的2017年

发表于 2017-01-01 | | 阅读次数

好像是忙了很多,不知道是懒了?好像是懒了。不怎么去思考了,也不怎么爱读了,总想无所事事的发呆。
二〇一六年,重要的,要谈谈什么。
这一年,终于,成为了一个北漂。和想象中的也不太一样,没有那么简单,一切都是从头开始,也没有那么困难,有一群真挚的朋友。终究是新的环境,面临着各种抉择和挑战,有关能力,有关事业,有关未来,也会迷茫。
这一年,体会到,人生,无论是做人,还是生活,都没那么容易,开始慢慢变得现实。有时候会回忆,思考曾经的一些选择是不是正确,由梦想主义的思考方式,变得理想,最后成为现实主义式的去选择。
这一年,不断的想,自己到底喜欢什么,能做什么,要做什么。好像变得有些胆怯了,害怕选择错误,害怕走弯路,尽管知道,自己还需要挫折的磨练。
不得不说,性格还在不断的变化。用自恋的话,正在学着更包容,更理性。以前特别容易冲动,某个决定,某个行为,可能一瞬间就做了出来。
因为爱情,开始郑重考虑、调整自己的发展,平衡家庭和事业。
感谢二〇一六有你,感谢二〇一七有你,感谢此生有你。
关于爱情,我试着找一些话去描述这份美好,却不想太坦白,爱情很简单,我会用行动温暖,执子之手,与子偕老,陪伴会是最长情的告白。
我曾把二〇一五年留给了自己,关于二〇一七,属于你我,家庭、事业。
有幸看节目关于玩儿一辈子和拼一辈子那个重要听到于老师这样说:玩儿是一种心态,玩儿好了就是拼,这种东西是不能分开的,因为你的事业如果想干好,你要下功夫,那么如果你要有一种玩的心态的话,你下的功夫你不觉得苦,如果你要没有爱好作为基础的话,你这下的功夫,永远是吃不尽的苦,到最后你还得不到,因为你并不喜欢它。
当初听到这些话的时候感触蛮深,适合自己的就是最好的。
新的一年,完成未完的篇章,开启全新的篇章。
在一起,我们携手同行。

畅畅的烧烤店

Python学习开发过程的小愉快

发表于 2016-09-13 | | 阅读次数

小愉快1:

在Python中,判断在某些条件下给变量赋值一句代码就能搞定:

1
multiple = 1024 if aTrue else 1000

在其他语言中:

1
2
3
4
5
multiple = 1
if a_kilobyte_is_1024_bytes:
multiple = 1024
else:
multiple = 1000

很简洁,有没有?哈呼。

畅畅的烧烤店

Pod制作公共库时遇到的问题

发表于 2016-08-22 | | 阅读次数

to find a pod with name, author, summary, or descriptionmatching ‘SKMoviePlayer’```
1
2
3
4
关于发布代码到CocoaPods(Trunk方式)上,就不多说了,可以看官方文档,看不懂的话网上有很多手把手教程。
当时我用 pod trunk 注册账户的时候,由于选择的用户名和github.com上面的不一致,导致发布之后搜索 SKMoviePlayer 库的时候一直出现文章开头的错误 ```(Unable to find a pod with name, author, summary, or descriptionmatching ‘SKMoviePlayer’)```。
于是,我就把帐号和邮箱改成和github上面的帐号信息一致了。过程如下:
### 首先执行了```pod trunk me``` 信息如下(与github上面的仓库帐号不一致):

bogon:~ Leou$ pod trunk me

  • Name: Leou
  • Email: wly314sdx@qq.com
  • Since: August 19th, 03:20
  • Pods:
    • SKMoviePlayer
  • Sessions:
    • August 19th, 03:20 - December 25th, 04:46. IP: 119.57.115.175 Description: MacBook
      Pro
    • August 21st, 20:34 - December 27th, 20:44. IP: 119.57.115.175
      1
      2
      3
      ### 执行 ```pod trunk register --help``` 看看有什么能改本地信息的么:
      If you’ve already registered with trunk, you may omit the `NAME`
      (unless you would like to change it)。所以我们可以通过```$ pod trunk register eloy@example.com```命令更改账户,那么好,去注册一个与github用户名一样的账户。

bogon:desktop Leou$ pod trunk register –help
Usage:

$ pod trunk register EMAIL [NAME]

  Register a new account, or create a new session.

  If this is your first registration, both an `EMAIL` address and your `NAME` are required. If you’ve already registered with trunk, you may omit the `NAME`

(unless you would like to change it).

It is recommended that you provide a description of the session, so that it will be easier to identify later on. For instance, when you would like to clean-up

your sessions. A common example is to specify the location where the machine,
that you are using the session for, is physically located.

Examples:

    $ pod trunk register eloy@example.com 'Eloy Durán' --description='Personal Laptop'
    $ pod trunk register eloy@example.com --description='Work Laptop'
    $ pod trunk register eloy@example.com
1
### 执行 ```pod trunk register eloy@example.com 'Eloy Durán' --description='Personal Laptop'```:

pod trunk register 783459987@qq.com ‘wly314’ –description=’MacBook Pro’

1
2
成功之后,去邮箱验证,这一步是为了注册另一个账户,然后就可以切换到新建的账户上。
之后就可以执行```pod trunk register 783459987@qq.com```重新建立本地会话,验证邮箱之后,执行```pod trunk me```信息如下:

bogon:desktop Leou$ pod trunk me

  • Name: wly314
  • Email: 783459987@qq.com
  • Since: August 21st, 20:28
  • Pods:
    • SKMoviePlayer
  • Sessions:
    • August 21st, 20:28 - December 27th, 20:34. IP: 119.57.115.175
    • August 21st, 21:36 - December 27th, 21:36. IP: 119.57.115.175 Description: MacBook Pro
      1
      2
      3
      OK,问题解决到现在就快差不多了,本地已经没什么问题,现在更改仓库的 Owner。
      ### 更改仓库 Owner:
      #### 看看现在仓库的Owner:目前属于```Leou```账户。

bogon:SKMoviePlayer Leou$ pod trunk info SKMoviePlayer
SKMoviePlayer

- Versions:
  - 0.0.2 (2016-08-19 09:27:39 UTC)
  - 0.0.3 (2016-08-19 09:55:45 UTC)
  - 0.0.4 (2016-08-19 10:46:17 UTC)
  - 0.0.5 (2016-08-22 02:40:34 UTC)
- Owners:
  - Leou <wly314sdx@qq.com>
1
2
#### 添加一个账户:```+ add-owner Add an owner to a pod```将新建的账户添加到pod库里。
如下我们可以看到有两个账户了,然后可以删除```Leou```。

bogon:desktop Leou$ pod trunk add-owner SKMoviePlayer 783459987@qq.com

  • Owners:
    • Leou wly314sdx@qq.com
    • wly314 783459987@qq.com
      1
      #### 删除```Leou```账户:```+ remove-owner Remove an owner from a pod

如下我们可以看到

1
2
3
4
```
bogon:desktop Leou$ pod trunk remove-owner SKMoviePlayer wly314sdx@qq.com
- Owners:
- wly314 <783459987@qq.com>

最后更新一下 SKMoviePlayer 文件:

如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Pod::Spec.new do |s|
s.name = "SKMoviePlayer"
s.version = "0.0.7"
s.summary = "SKMoviePlayer一个在完善中的播放器-基于AVPlayer"
s.description = <<-DESC
SKMoviePlayer一个在完善中的播放器-基于AVPlayer
必须是addSubview添加播放器SKMoviePlayer。
DESC
s.homepage = "https://wly314.github.io"
s.license = "MIT"
s.author = { "wly314" => "783459987@qq.com" }
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/wly314/SKMoviePlayer.git", :tag => "0.0.7" }
s.source_files = "SKMoviePlayer", "*.{h,m}"
s.resources = 'SKMoviePlayer/SKImages/*.{png,jpg}'
s.requires_arc = true
end

OK,现在问题已经解决。搜索一下库pod search SKMoviePlayer,可以看到,搜索已经成功。

畅畅的烧烤店

App重构计划

发表于 2016-08-11 | | 阅读次数

简单的是语言,深层地做研究,别让程序打败了自己。

1. 第三方库管理

CocoaPods 管理第三方库。第三方库以每个大的版本号为一次稳定版本,当前项目使用稳定版本,如果第三方库有大版本升级,则可以根据项目是否对第三方库进行升级。

1
2
3
例如:
pod 'AFNetworking', '~> 3.0',意思为项目当前使用的AFNetworking为4.0.0以下最新版本。
如果AFNetworking升级到4.0.0,则根据自己的项目考虑是否升级,如果升级,只需要Podfile更改为:pod 'AFNetworking', '~> 4.0',然后执行 pod update 即可。

项目中使用以下第三库:

1
2
3
4
5
6
AutoLayout布局管理: Masonry,本次使用版本2.0以下版本。
数据请求: AFNetworking,本次使用版本2.0以下版本。
网络图片加载与缓存: SDWebImage,本次使用版本2.0以下版本。
下拉刷新、上拉加载: MJRefresh,本次使用版本2.0以下版本。
数据库: FMDB,本次使用版本2.0以下版本。
网络加载指示器 MBProgressHUD,本次使用版本2.0以下版本。

Podfile 如下:

1
2
3
4
5
6
7
8
9
10
11
12
platform:ios, '7.0'
target "VKVickey_NCE" do
pod 'Masonry', '~> 1.0'
pod 'AFNetworking', '~> 3.0'
pod 'SDWebImage', '~> 3.0'
pod 'MJRefresh', '~> 3.0'
pod 'FMDB', '~> 2.0'
pod 'MBProgressHUD', '~> 1.0'
end

2. 代码规范

代码规范参照以下标准:

  • iOS开发代码规范 (待完善)
  • iOS重构注意事项 (待完善)
畅畅的烧烤店

代码规范

发表于 2016-07-28 | | 阅读次数

1. 命名规则:

a) 类名首字母大写,方法首字母小写,方法中的参数首字母小写。所有命名采用驼峰命名法。
b) 所有命名不允许与系统参数命名一致,例如:

1
UITableView *tableView。

c) 宏定义命名大写字母,能直观表达出宏定义的含义,单词之间以下划线隔开,例如:

1
#define DISPATCH_SOURCE_TYPE_TIMER。

d) 命名禁止使用单字母,应该尽量能表达变量含义,而且要有注释解释说明。
e) 私有变量的声明命名。
f) 全局变量的声明命名。
g) 方法的声明命名。
h) 资源命名规则:见第5条。

2. 注释

a) 所有的需要注释的地方:类文件的解释,变量或参数的解释,方法的解释,宏定义的解释,代码逻辑的解释等。
b) #pragma mark - 或者 // MARK: 标记分类。
c) 所有注释尽量采用代码块注释:/* 这样的注释 /。
d) 解释类注释必须采用代码块注释。例如:方法名解释,版权解释,类解释,变量或参数解释等。
e) 对OC:私有变量或方法的声明一律写进实现文件.m中。
f) 推荐使用插件:VVDocumenter-Xcode

3. 对齐、换行与缩进

a) {}:{ 跟在外部代码后面的,内部代码与上 { 之间保持一个换行。{ 与外部代码另起一行的,内部代码不必另起一行。{}
b) 代码块与代码块之间,必须保持换行(空一行或两行),不允许出现从上到下一堆。
c) @关键字与代码保持空一行。
d) 所有代码必须保持对齐。

4. 空格

a) 运算符前后必须加空格。
b) 多参数,每个参数的逗号后必须加空格,例如:time(x, y)。
c) 星号 与类型必须有一个空格,与变量之间无空格,例如:NSString str。

5. 资源命名规则

资源命名全部使用小写字母,单词之间以下划线分隔,应能充分表达意思,以前缀区分资源,防止重名,以后缀区分资源类型(比如图片正常状态,高亮状态等)。

6. 编码

保证每一行代码都要简洁、明了:

不提倡非规范代码:
1
unitYuXi.navigationItem.title = [[[skListArray objectAtIndex:indexPath.section] objectForKey:@"units"] objectForKey:@"title"];
提倡规范代码:
1
2
3
NSDictionary *msgDict = [skListArray objectAtIndex:indexPath.section];
NSDictionary *unitsDict = [msgDict objectForKey:@"units"];
unitYuXi.navigationItem.title = [unitsDict objectForKey:@"title"];

模块化开发

代码尽可能功能模块化,所有代码文件保证1000行代码之内。
封装:把模块化的功能全部封装出来,封装时要注意,只处理功能效果,不负责业务逻辑处理。

畅畅的烧烤店

获取图片像素信息

发表于 2016-04-05 | | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
- (NSArray*)getRGBAsFromImage:(UIImage*)image atX:(int)x andY:(int)y count:(int)count
{
NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:count];
// First get the image into your data buffer
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = (unsigned char*) calloc(height * width * 4, sizeof(unsigned char));
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
NSUInteger byteIndex = (bytesPerRow * y) + x * bytesPerPixel;
for (int i = 0 ; i < count ; ++i)
{
CGFloat alpha = ((CGFloat) rawData[byteIndex + 3] ) / 255.0f;
CGFloat red = ((CGFloat) rawData[byteIndex] ) / alpha;
CGFloat green = ((CGFloat) rawData[byteIndex + 1] ) / alpha;
CGFloat blue = ((CGFloat) rawData[byteIndex + 2] ) / alpha;
byteIndex += bytesPerPixel;
UIColor *acolor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[result addObject:acolor];
}
free(rawData);
return result;
}

来自: http://stackoverflow.com/questions/448125/how-to-get-pixel-data-from-a-uiimage-cocoa-touch-or-cgimage-core-graphics.
欢迎交流。

畅畅的烧烤店

CocoaPods

发表于 2015-10-28 | | 阅读次数

参考:
http://www.cnblogs.com/wayne23/p/3912882.html.

OS X系统已经安装过Ruby了,因此我们只需执行以下命令:

1
sudo gem install -n /usr/local/bin cocoapods

由于某些原因,执行时会出现下面的错误提示:

1
2
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::EPIPE: Broken pipe - SSL_connect (https://rubygems.org/latest_specs.4.8.gz)

可以多试几次,或者使用淘宝的代理,执行以下命令。

1
2
3
4
$ gem sources -l
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l

然后重新安装:

1
sudo gem install -n /usr/local/bin cocoapods

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
安装成功后,接着执行命令:
pod setup<br>
如果Ruby环境不够新,可能需要更新以下:
sudo gem update --system<br>
至此安装就完成了,我们可以尝试搜索一个第三方类库:
pod search AFNetworking<br>
使用CocoaPods的第一步,是在当前项目下,新建一个Podfile文件:
touch Podfile<br>
然后利用vim打开Podfile文件编辑,加入你想要使用的类库,格式如下:
platform :ios
pod 'Reachability', '3.1.0'
platform:ios, '6.0'
pod 'JSONKit','1.4'
pod 'AFNetworking', '~> 2.3.1'<br>
如果是拷贝的别人的项目,或是一个很久没打开过的项目,可能需要先执行一下:
pod update<br>
最后一步,执行命令:
pod install<br>
当终端出现类似下面的提示后,就代表成功了:
[!] From now on use `Sample0814.xcworkspace`.<br>
这个时候会看到项目文件夹下多了一个文件xxx.xcworkspace,以后要通过这个文件打开项目,老项目文件xxx.xcodeproj不再使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
P.s.1 上面的每一步都有可能出现问题,但大部分问题都是因为大局域网的原因,用一个网速稳定的境外VPN可破。
P.s.2 如果上面因为权限问题安装失败,必须每次都要删除
rm -rf /Users/loginnanme/Library/Caches/CocoaPods/
因为这个缓存中会存下你的github的东西,造成每次都调用上次权限问题的缓存。
P.s.3 关于Podfile文件编辑时,第三方库版本号的各种写法:
复制代码
pod ‘AFNetworking’ //不显式指定依赖库版本,表示每次都获取最新版本
pod ‘AFNetworking’, ‘2.0’ //只使用2.0版本
pod ‘AFNetworking’, ‘>2.0′ //使用高于2.0的版本
pod ‘AFNetworking’, ‘>=2.0′ //使用大于或等于2.0的版本
pod ‘AFNetworking’, ‘<2.0′ //使用小于2.0的版本
pod ‘AFNetworking’, ‘<=2.0′ //使用小于或等于2.0的版本
pod ‘AFNetworking’, ‘~>0.1.2′ //使用大于等于0.1.2但小于0.2的版本,相当于>=0.1.2并且<0.2.0
pod ‘AFNetworking’, ‘~>0.1′ //使用大于等于0.1但小于1.0的版本
pod ‘AFNetworking’, ‘~>0′ //高于0的版本,写这个限制和什么都不写是一个效果,都表示使用最新版本
畅畅的烧烤店

iOS 从绘图开始:DrawRect&CoreText

发表于 2015-08-05 | | 阅读次数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
- (void)drawRect:(CGRect)rect {
// Drawing code
//Quartz 2D绘画环境,一张画布
CGContextRef context = UIGraphicsGetCurrentContext();
//边框圆 背景圆
CGContextSetRGBStrokeColor(context,1,1,0,1.0);//画笔线的颜色
CGContextSetLineWidth(context, 2.0);//线的宽度
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1弧度=180°/π (≈57.3°) 度=弧度×180°/π 360°=360×π/180 =2π 弧度
// x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
CGContextAddArc(context, 120, 120, 100, 0, 2*M_PI, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
//所占比例圆弧
CGContextSetRGBStrokeColor(context,1,0,0,1.0);//画笔线的颜色
CGContextSetLineWidth(context, 3.0);//线的宽度
CGContextAddArc(context, 120, 120, 100, -90 * M_PI/180, (endRadius-90) * M_PI/180, 0); //添加一个圆
CGContextDrawPath(context, kCGPathStroke); //绘制路径
//绘制字符串
if ([[UIDevice currentDevice] systemVersion].floatValue >= 7.0) {
NSMutableAttributedString *mabstring = [[NSMutableAttributedString alloc]initWithString:drawText];
[mabstring beginEditing];
//对同一段字体进行多属性设置
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithObject:(id)[UIColor redColor].CGColor forKey:(id)kCTForegroundColorAttributeName];//红色字体
//设置字体属性
CTFontRef font = CTFontCreateWithName(CFSTR("Georgia"), 14, NULL);
[attributes setObject:(id)(__bridge id)font forKey:(id)kCTFontAttributeName];//下划线
[mabstring endEditing];//结束编辑
[mabstring addAttributes:attributes range:NSMakeRange(0, mabstring.length)];
//开始绘制
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)mabstring);
CGMutablePathRef Path = CGPathCreateMutable();
CGPathAddRect(Path, NULL ,CGRectMake(100 , -100 ,self.bounds.size.width-10 , self.bounds.size.height-10));
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), Path, NULL);
//压栈,压入图形状态栈中.
CGContextSetTextMatrix(context , CGAffineTransformIdentity);
//保存现在得上下文图形状态。
CGContextSaveGState(context);
//x,y轴方向移动
CGContextTranslateCTM(context , 0 ,self.bounds.size.height);
//缩放x,y轴方向缩放,代码中坐标系转换是沿x轴翻转180度
CGContextScaleCTM(context, 1.0 ,-1.0);
CTFrameDraw(frame,context);//开始绘制大小
CGPathRelease(Path);//开始绘制路径
CFRelease(framesetter);
}else {
//表示开始绘制路径
CGContextBeginPath(context);
//设置文字大小
CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
// 设置文本颜色字符为白色
CGContextSetRGBFillColor(context, 1.0, 0.0, 1.0, 1.0); //白色
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
//绘制文字
CGContextShowTextAtPoint(context,20, 100, [@"characterAttribute" cStringUsingEncoding:[NSString defaultCStringEncoding]],
@"characterAttribute".length);
CGContextStrokePath(context);
//表示结束绘制路径
CGContextClosePath(context);
}
/////////////////////一些字体属性设置////////////////////////
// [mabstring addAttribute:(id)kCTFontAttributeName value:(__bridge id)font range:NSMakeRange(0, 4)];
// [attributes setObject:(id)[NSNumber numberWithInt:kCTUnderlineStyleDouble] forKey:(id)kCTUnderlineStyleAttributeName];//下划线
// [mabstring addAttributes:attributes range:NSMakeRange(0, 4)];//设置属性的文字范围
//设置斜体字
// CTFontRef font = CTFontCreateWithName((CFStringRef)[UIFont italicSystemFontOfSize:20].fontName, 14, NULL);
// [mabstring addAttribute:(id)kCTFontAttributeName value:(__bridge id)(font) range:NSMakeRange(0, 4)];
}

上面的代码,是在UIView上绘制一个圆形比例图和文字。

下面是CoreText在Label上的使用。

1
2
3
4
5
6
7
8
9
10
11
12
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 2, sectionHeader.bounds.size.width-60-15-10, 56)];
titleLabel.font = [UIFont systemFontOfSize:17.0f];
[sectionHeader addSubview:titleLabel];
NSString *titleStr = [NSString stringWithFormat:@"你还有%ld未通过", courseCount];
NSInteger courseCount = [obligatoryCourseArray count];
// 设置标签文字
NSMutableAttributedString *attrituteString = [[NSMutableAttributedString alloc] initWithString:titleStr];
// 设置标签文字的属性
[attrituteString setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor], NSFontAttributeName : [UIFont systemFontOfSize:25]} range:NSMakeRange(3, [NSString stringWithFormat:@"%ld", courseCount].length)];
// 显示在Label上
titleLabel.attributedText = attrituteString;

当然Label上绘制的Text的属性可以用上面的在UIView上绘制中的方法。

再来看一个UIImageView的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
UIImageView *obligatoryImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, tableView.bounds.size.width, ([UIScreen mainScreen].bounds.size.height-20-44)/3-30*2)];
[cell addSubview:obligatoryImageView];
obligatoryImageView.backgroundColor = [UIColor whiteColor];
UIGraphicsBeginImageContext(obligatoryImageView.bounds.size);
[obligatoryImageView.image drawInRect:CGRectMake(0, 0, obligatoryImageView.bounds.size.width, obligatoryImageView.bounds.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //边缘样式
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 0.2); //线宽
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),153/255.0,153/255.0,153/255.0,1.0); //颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 35, 5); //起点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, 5);//终点坐标
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, (obligatoryImageView.bounds.size.height-5));
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, (obligatoryImageView.bounds.size.height-5));
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, 5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, (obligatoryImageView.bounds.size.height-5)/5+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, (obligatoryImageView.bounds.size.height-5)/5+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, (obligatoryImageView.bounds.size.height-5)/5*2+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, (obligatoryImageView.bounds.size.height-10)/5*2+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, (obligatoryImageView.bounds.size.height-10)/5*3+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, (obligatoryImageView.bounds.size.height-10)/5*3+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), self.view.bounds.size.width-35, (obligatoryImageView.bounds.size.height-10)/5*4+5);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 35, (obligatoryImageView.bounds.size.height-10)/5*4+5);
CGContextStrokePath(UIGraphicsGetCurrentContext());
obligatoryImageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSArray *obligatoryArray = [courseArray objectAtIndex:indexPath.row];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
titleLabel.textColor = [UIColor murpTextLowColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = [UIFont systemFontOfSize:15.0f];
titleLabel.text = [[obligatoryArray objectAtIndex:0] objectForKey:@"Extend2"];
[cell addSubview:titleLabel];
for (int i = 0; i <= 5; i ++) {
UILabel *left1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 30+(obligatoryImageView.bounds.size.height-10)/5*i, 35, 10)];
left1.textColor = [UIColor murpTextLowColor];
left1.textAlignment = NSTextAlignmentRight;
left1.font = [UIFont systemFontOfSize:12.0f];
left1.text = [NSString stringWithFormat:@"%d%%", 100-20*i];
[cell addSubview:left1];
if (i < obligatoryArray.count-1) {
UILabel *down = [[UILabel alloc] initWithFrame:CGRectMake(35+(tableView.bounds.size.width-35*2)/5*i, ([UIScreen mainScreen].bounds.size.height-20-44)/3-30, (tableView.bounds.size.width-35*2)/5, 30)];
down.textColor = [UIColor murpTextLowColor];
down.textAlignment = NSTextAlignmentCenter;
down.font = [UIFont systemFontOfSize:12.0f];
[cell addSubview:down];
down.text = [NSString stringWithFormat:@"%@分",[[obligatoryArray objectAtIndex:i+1] objectForKey:@"Extend1"]];
CGFloat heights = [[[obligatoryArray objectAtIndex:i+1] objectForKey:@"Extend3"] floatValue]/100.0*(obligatoryImageView.bounds.size.height-5*2);
UIImageView *heightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(35+(tableView.bounds.size.width-35*2)/5*i+5, (([UIScreen mainScreen].bounds.size.height-20-44)/3-30-5)-heights, (tableView.bounds.size.width-35*2)/5-10, heights)];
heightImageView.backgroundColor = [UIColor murpThemeGreenColor];
[cell addSubview:heightImageView];
UILabel *heightsLabel = [[UILabel alloc] initWithFrame:CGRectMake(35+(tableView.bounds.size.width-35*2)/5*i+5, (([UIScreen mainScreen].bounds.size.height-20-44)/3-30-5)-heights-20, (tableView.bounds.size.width-35*2)/5-10, 20)];
heightsLabel.textColor = [UIColor murpTextLowColor];
heightsLabel.textAlignment = NSTextAlignmentCenter;
heightsLabel.font = [UIFont systemFontOfSize:10.0f];
[cell addSubview:heightsLabel];
heightsLabel.text = [[obligatoryArray objectAtIndex:i+1] objectForKey:@"Extend2"];
}
}
}

看一眼效果图:
图

畅畅的烧烤店

iOS设置导航与其标题的颜色及字体大小和系统默认TabBar的相关设置与使用方法

发表于 2015-04-07 | | 阅读次数

第一步:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//在info.plist中添加一个字段:view controller -base status bar 设置为NO;
//导航颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor XXXX]];
[[UITableViewCell appearance] setBackgroundColor:[UIColor XXXX]];
//设置状态栏(信号区)白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
//默认带有一定透明效果,可以使用以下方法去除系统效果
[navigationController.navigationBar setTranslucent:NO];
//更改导航标题字体大小与颜色要在第一级页面设置 如下
// 设置导航默认标题的颜色及字体大小
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: [UIColor whiteColor], UITextAttributeFont:[UIFont boldSystemFontOfSize:18]};

第二步:

//UIImageRenderingModeAlwaysOriginal 让图片表现的模式为图片的原始样式 用于去掉系统添加的颜色
self.tabBarController.tabBarItem.title = @"title";
if ([[UIDevice currentDevice] systemVersion].floatValue >= 7.0) {

[self.tabBarController.tabBarItem setFinishedSelectedImage:[[UIImage imageNamed:@"Image.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] withFinishedUnselectedImage:[[UIImage imageNamed:@"ImageS.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}else{
[self.tabBarController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"Image.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"ImageS.png"]];
}
//tabbar颜色 用于更改字体颜色
[self.tabBarController.tabBar setTintColor:[UIColor XXXX]];

Demo地址:
This is https://github.com/wly314/HappyTravel.
欢迎交流。

畅畅的烧烤店

Hello World

发表于 2014-11-14 | | 阅读次数

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

Leou

Leou

iOS开发笔记,Python历程,微信公众号玩出花样

10 日志
© 2017 Leou
由 Hexo 强力驱动
主题 - NexT.Pisces