催眠术的博客


  • 首页

  • 归档

iPhone开发-Keyboard

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

文本经常需要和键盘打交道,现在记录一下初步的键盘相关的知识点。
键盘出现和消失促发两个消息。

UIKeyboardWillShowNotification (出现通知)
UIKeyboardWillHideNotification (隐藏通知)

NSNotificationCenter 监听两个消息即可捕捉到键盘弹出和隐藏的两个消息。

阅读全文 »

iPhone开发-GCD

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

一些常用的API

阅读全文 »

iPhone开发-UIImage,CIImage,CGImageRef

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

UIImage 有很多有用的东西,前段时间接触了coreImage的API,发现有一个CIImage的东西,同样还有一个CGImage的东西,这三者总是可以切换起来,多少让人觉得这个东西很能耐。
IOS编程揭秘 书中记录着如下一段话。

1
2
UIImage类的Core Graphics
版本是CGImage(CGImageRef)这两个类之间很容易进行转换,因为一个UIImage类有一个CGImage的属性“
阅读全文 »

iPhone开发-UILabel

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

UILable 的用法涉及内容有如下

  1. 创建与显示
  2. 文本内容和字体设置
  3. 背景颜色指定
  4. 计算高度。
  5. 行数指定和计算

UIlabel可以显示指定的行数,设置numberOfLines =0 则为不限制行数,因为UIlabel不是Icontrol的方面,没有addTarget和block等方法处理相应的行为机制,但支持扩展手势触控等方法处理点击,不过对于html 超链接响应情况,在之前看过是需要采用第三方处理机制处理。

在日常使用过程,对于文本方法计算高度的用法很常用,ios提供相应计算方法。如属于NSString的类别(NSStringDrawing.h)该类为此提供相应处理解决方案,提供计算高度和文本大小的方法。
注意到 过去ios6的版本 提供sizeWithFont方法 在ios 7.0 已经不生效,需要改成其他方法处理。boundingRectWithSize 后续推荐的方式。

1
- (CGSize)sizeWithAttributes:(NSDictionary *)attrs NS_AVAILABLE_IOS(7_0);
1
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context NS_AVAILABLE_IOS(7_0);
1
2
3
4
5
6
7
8
 self.label = [[UILabel alloc]initWithFrame:CGRectMake(85, 0, self.view.frame.size.width-85, 70)];
[self.panel addSubview:self.label];
self.label.text = @"这个人很懒,什么都没留下";
self.label.numberOfLines = 3;
self.label.lineBreakMode = NSLineBreakByCharWrapping;
self.label.font =[UIFont systemFontOfSize:14];
// self.label.userInteractionEnabled = YES; 需要的时候才打开
[self.view addSubview:self.panel];

下面计算一下高度,当采用默认字体的时候,字体号为17,其高度约为20, 字体为14的时候,高度约为16~17之间

1
2
3
4
字体号:17 ,文本高:20
字体号:16 ,文本高:19
字体号:15 ,文本高:17~18 之间
字体号:14, 文本高:16~17 之间

这些字体是默认字体,要是采用其他字体或者设置粗体 ,估计值会受到一些浮动影响。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[self getTextHeight:17 width:self.view.frame.size.width-85];   
-(void) getTextHeight:(CGFloat) fontSize width:(CGFloat) textWidth
{

NSDictionary *dic =@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
CGSize curSize = CGSizeMake(textWidth, MAXFLOAT);
CGRect rect = [self.label.text boundingRectWithSize:curSize
options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
attributes:dic context:nil];

NSString *str = NSStringFromCGRect(rect);
NSLog(@"%@",str);

}

iPhone开发-leftBarButtonItem

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

1.设置leftBarButtonItem的文字

在设置 leftBarButtonItem的时候,又会少了一个左箭头。

一般情况下,自定义一个新的标题会这样操作,设置完成后,问题来了,发现左箭头不见了。

1
self.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self  action:@selector(onSelect)];

一般情况下,自定义 UIBarButtonItem 使用设置图片有如下,但发现文本不能设置显示了。

1
2
[[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStylePlain target:self
action:@selector(onSelect)];

还有一种方式,既有文本又有左箭头的需求,只能使用下面这种方式,自定义一个按钮视图。

1
[[UIBarButtonItem alloc]initWithCustomView:backButton];

问题前提: 使用pushViewController的时候,该界面返回情况会默认是上一级的标题, 更改文字,又会对本身产生影响。原本意图很简单,就是想设置自己的文字,又想有左箭头。

1
[self.navigationController pushViewController:cityController animated:YES];

阅读全文 »

iPhone开发-截屏

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

iPhone 截屏并本地存储

使用UIGraphicsBeginImageContext 相关绘图API 获取到图像信息,使用UIImageWriteToSavedPhotosAlbum 方法就可以保存到相关的库里面去

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UIWindow *window =[UIApplication sharedApplication].keyWindow;
UIGraphicsBeginImageContext(window.frame.size);
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

-(void) image:(UIImage *) image didFinishSavingWithError:(NSError *) error contextInfo:(void *) contextInfo
{
if (error != NULL)
{
NSLog(@"保存失败");
}
else
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"保存成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alertView show];
}

}

iPhone开发-常用组件

发表于 2017年11月15日 | 分类于 ios | | 阅读次数:

1. UIButton

1
2
3
4
5
6
7
8
9
10
11
12
CGRect frame = CGRectMake(0, 100, 80, 40);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
[button setTitle:@"click" forState: UIControlStateNormal];
button.backgroundColor = [UIColor greenColor];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

-(void) buttonClicked:(UIButton *)button
{
//添加code
}

2. UIAlertView

1
2
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"标题" message:@"你的内存已满" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
[alert show];
阅读全文 »

Github 安全类Repo收集整理[转载]

发表于 2017年09月11日 | 分类于 github | | 阅读次数:

漏洞及渗透练习平台:
WebGoat漏洞练习环境
https://github.com/WebGoat/WebGoat
https://github.com/WebGoat/WebGoat-Legacy
Damn Vulnerable Web Application(漏洞练习平台)
https://github.com/RandomStorm/DVWA
数据库注入练习平台
https://github.com/Audi-1/sqli-labs
用node编写的漏洞练习平台,like OWASP Node Goat
https://github.com/cr0hn/vulnerable-node

阅读全文 »

命名规则-阿里巴巴Java开发

发表于 2017年08月08日 | 分类于 java | | 阅读次数:
  1. 【强制】 代码中的命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束。
    反例: name / __name / $Object / name / name$ / Object$
阅读全文 »

升级Xcode后Qt问题了

发表于 2017年01月23日 | 分类于 qt | | 阅读次数:

升级XCode后,Qt新建项目出现了问题:

Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.

阅读全文 »
1…678…10
催眠术

催眠术

催眠术的技术博客

98 日志
23 分类
79 标签
© 2022 催眠术
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4