Skip to content

Instantly share code, notes, and snippets.

//@property (nonatomic, assign) NSInteger lastcontentOffset; //添加此属性的作用,根据差值,判断ScrollView是上滑还是下拉
//<UIScrollViewDelegate >
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat hight = scrollView.frame.size.height;
CGFloat contentOffset = scrollView.contentOffset.y;
CGFloat distanceFromBottom = scrollView.contentSize.height - contentOffset;
CGFloat offset = contentOffset - self.lastcontentOffset;
self.lastcontentOffset = contentOffset;
UILabel *headerTitle = [[UILabel alloc] init];
headerTitle.text = NSLocalizedString(@"profile_language_limit", @"语言最多只能选择3个");
headerTitle.textColor = [UIColor colorNamed:@"secondaryTextColor"];
headerTitle.font = [UIFont fontWithName:@"Roboto-Regular" size:11];;
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
headerView.backgroundColor = [UIColor colorNamed:@"mainBackgroundColor"];
[headerView addSubview:headerTitle];
[headerTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.mas_equalTo(16);
//一级指定本地pod文件
//:path => 指定本地路径
pod 'XXSdk',:path => 'XXSdkLib'
//2级本地pod
pod 'Gonfig',:path => '../Gonfig'
//demo使用第二级pod
pod 'A',:path => 'A podspec 文件夹'
@qy1010
qy1010 / iOS
Created November 27, 2019 02:08
//保存图片到相册
//image是要保存的图片
- (void) saveImage:(UIImage *)image{
if (image) {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
};
}
//将Objective-C代码转换为C\C++代码
xcrun -sdk iphoneos clang -arch arm64 -rewrite-objc OC源文件 -o 输出的CPP文件
如果需要链接其他框架,使用-framework参数。比如-framework UIKit
@qy1010
qy1010 / path
Created November 26, 2019 12:06
// 项目内黄色文件夹路径
NSString *faceEmojiDir = [[NSBundle mainBundle] pathForResource:@"maoboli" ofType:@"ofeffect"];
unsigned int count;
//获取属性列表
objc_property_t *propertyList = class_copyPropertyList([self class], &count);
for (unsigned int i=0; i<count; i++) {
const char *propertyName = property_getName(propertyList[i]);
NSLog(@"property---->%@", [NSString stringWithUTF8String:propertyName]);
}
//获取方法列表
Method *methodList = class_copyMethodList([self class], &count);
//可以看出class_createInstance和alloc的不同
id theObject = class_createInstance(NSString.class, sizeof(unsigned));
id str1 = [theObject init];
NSLog(@"%@", [str1 class]);
id str2 = [[NSString alloc] initWithString:@"test"];
NSLog(@"%@", [str2 class]);
Class cls = objc_allocateClassPair(MyClass.class, "MySubClass", 0);
class_addMethod(cls, @selector(submethod1), (IMP)imp_submethod1, "v@:");
class_replaceMethod(cls, @selector(method1), (IMP)imp_submethod1, "v@:");
class_addIvar(cls, "_ivar1", sizeof(NSString *), log(sizeof(NSString *)), "i");
objc_property_attribute_t type = {"T", "@\"NSString\""};
objc_property_attribute_t ownership = { "C", "" };
objc_property_attribute_t backingivar = { "V", "_ivar1"};
objc_property_attribute_t attrs[] = {type, ownership, backingivar};
@qy1010
qy1010 / runtime
Last active November 21, 2019 12:09
对对象类的操作:
// 返回给定对象的类名
const char * object_getClassName ( id obj );
// 返回对象的类
Class object_getClass ( id obj );
// 设置对象的类
Class object_setClass ( id obj, Class cls );
获取对象的类定义