Skip to content

Instantly share code, notes, and snippets.

@qy1010
qy1010 / AttributedString
Last active June 13, 2019 08:06
有图片文字AttributedString
- (NSAttributedString *)bounusString:(NSString *)bounusText
{
NSMutableAttributedString *msg = [[NSMutableAttributedString alloc] init];
UIFont *textFont = [UIFont fontWithName:@"Roboto-Regular" size:13];
NSTextAttachment *dimondAttachment = [[NSTextAttachment alloc] init];
dimondAttachment.image = [UIImage imageNamed:@"ico_dimond"];
dimondAttachment.bounds = CGRectMake(0, 0, 13, 13);
NSAttributedString *dimondatrri = [NSAttributedString attributedStringWithAttachment:dimondAttachment];
[msg appendAttributedString:dimondatrri];
@qy1010
qy1010 / PodFile
Last active July 8, 2019 08:21
PodFile 通用
# 增大点击区域
pod 'TouchAreaInsets', '1.1.0'
# popup tips 弹出黄色箭头提示
pod 'CMPopTipView', '2.3.2'
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
//渐变蒙层
@interface HTVGradientLayer : UIView
@end
NS_ASSUME_NONNULL_END
@qy1010
qy1010 / TableView
Created June 13, 2019 08:29
TableView高度自动调节
[self.KVOController observe:self.xxxx keyPath:FBKVOKeyPath(((UITableView *)_chatView).contentSize) options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
UITableView *xxxx1 = (UITableView *)object;
CGFloat heightT = xxxx1.contentSize.height;
CGFloat maxHeight = 200;
if (heightT > maxHeight) {
heightT = maxHeight;
}
git cherry-pick
CGRect rect = self.bounds;
// Create the path
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect
byRoundingCorners:corners
cornerRadii:CGSizeMake(radius, radius)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = rect;
@qy1010
qy1010 / coocapods
Last active September 19, 2019 08:56
安装coocapods
// 指安装最新 指定安装源
$ sudo gem install cocoapods --source http://rubygems.org
// 指定版本安装 指定安装源
$ sudo gem install cocoapods --source http://rubygems.org -v 1.5.3
查看pod版本
pod --version
查看有哪个pod
gem list pod
@qy1010
qy1010 / NSInvocation
Created July 2, 2019 09:07
NSInvocation create & invoke
// create
- (NSInvocation*)createInvocationWithSelector:(SEL)selector {
NSMethodSignature *signature = [self methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.target = self;
invocation.selector = selector;
return invocation;
}
//invoke
@qy1010
qy1010 / dispatch_semaphore_t
Created July 2, 2019 09:19
异步方法同步执行:信号量dispatch_semaphore
- (NSInteger)methodSync {
NSLog(@"methodSync Begin");
__block NSInteger result = 0;
//使用信号量dispatch_semaphore
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[self methodAsync:^(NSInteger value) {
result = value;
dispatch_semaphore_signal(sema);
}];
@qy1010
qy1010 / invoke
Created July 2, 2019 09:21
反射 init & invoke
//反射调用
Class <#your class#> = NSClassFromString(<#your class#>);
id <#instance#>= [[<#your class#> alloc] init];
SEL selector = NSSelectorFromString(<#CallFunc#>);
[<#instance#> performSelector:selector withObject:nil];