小笔记

//修改TextField placeholderLabel颜色
Ivar ivar =  class_getInstanceVariable([UITextField class], "_placeholderLabel");
UILabel *placeholderLabel = object_getIvar(_numberTextField, ivar);
placeholderLabel.textColor = COLOR_160;
//修改组头颜色
headerView.contentView.backgroundColor = COLOR_240;
//按钮对齐方式
_modelsButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
_titleButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
//初始化对话框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  [self.navigationController popViewControllerAnimated:YES];
}]];
[self presentViewController:alert animated:true completion:nil];
//在WKWebView加载页面后会发现页面的字会很小, 这是因为原网页没有做手机屏幕尺寸的适配, 那么在后台不做调整的情况下我们移动端怎样来适配页面
_webView = [[WKWebView alloc] init];
//以下代码适配大小
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
        
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController *wkUController = [[WKUserContentController alloc] init];
[wkUController addUserScript:wkUScript];
        
WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
wkWebConfig.userContentController = wkUController;
        
_webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame), WIDTH, HEIGHT/2 - 100) configuration:wkWebConfig];
[pool addSubview:_webView];
_webView.navigationDelegate = self;
//屏幕点击事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"点击了屏幕");
}
//判断是否为null
BOOL numberNull = [self isBlankString:_storeInfo.customer_number];
- (BOOL) isBlankString:(NSString *)string {
    if (string == nil || string == NULL) {
           return YES;
        }
    if ([string isKindOfClass:[NSNull class]]) {
           return YES;
        }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
           return YES;
        }
    return NO;
}
//数组循环删除元素
//逆序遍历
for (WearingPartsSpecialAttributesHeaderModel *headerModel in [self.headerDataArray reverseObjectEnumerator]) {
  if ([headerModel.name isEqualToString:@"配件品牌"]) {
      [self.headerDataArray removeObject:headerModel];
   }
}
#pragma mark - 重置导航
- (void)resetNav{
   self.titleLabel.text = @"发票管理";
   [self.backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
   UIButton *submitButton = [FactoryUI createButtonWithFrame:CGRectMake(SCREEN_W - 74, 0, 64, NavBarHigh) title:@"添加" titleColor:COLOR_Red font:Font28 backgroundColor:COLOR_17 type:UIButtonTypeCustom target:self selector:@selector(submitButtonClick)];
   [self.navigationView addSubview:submitButton];
}
#pragma mark - 按钮响应方法
- (void)backButtonClick{
    DLog(@"返回");
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)submitButtonClick{
    DLog(@"添加");
}
//按钮防重点
addButton.timeInterval = 2;
//纯数字键盘:
textField.keyboardType = UIKeyboardTypeNumberPad;
//纯数字加小数点键盘:
textField.keyboardType = UIKeyboardTypeDecimalPad;
//设置button图片填充整个按钮
//NSData *imgData = [self image_TransForm_Data:[UIImage imageNamed:@"shangchuan_lkjl"]];
//UIImage *image = [UIImage imageWithData:imgData];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.url]]];
CGFloat top = 0; // 顶端盖高度
CGFloat bottom = 0 ; // 底端盖高度
CGFloat left = 0; // 左端盖宽度
CGFloat right = 0; // 右端盖宽度
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
[self.mainButton setImage:image forState:UIControlStateNormal];
[self.mainButton setTitle:@"" forState:UIControlStateNormal];
- (NSData *)image_TransForm_Data:(UIImage *)image
{
    NSData *imageData = UIImageJPEGRepresentation(image, 0);
    //几乎是按0.5图片大小就降到原来的一半
    return imageData; 
}

//加载Base64图片
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:_qrCodeModel.miniCode options:NSDataBase64DecodingIgnoreUnknownCharacters];
_qrImgView.image = [UIImage imageWithData:imageData];
#pragma mark - 去除多余组尾
//组尾
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    //注册组尾
    [_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"FooterView"];
    UITableViewHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"FooterView"];
    footerView.backgroundColor = [UIColor cyanColor];
    return footerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001;
}
__weak __typeof(self) weakSelf = self;
int age=10;
void (^Block)(void) = ^{
    NSLog(@"age:%d",age);
};
age = 20;
Block();
//输出值为 age:10
//原因:创建block的时候,已经把age的值存储在里面了。

auto int age = 10;
static int num = 25;
void (^Block)(void) = ^{
    NSLog(@"age:%d,num:%d",age,num);
};
age = 20;
num = 11;
Block();
//输出结果为:age:10,num:11
//原因:auto变量block访问方式是值传递,static变量block访问方式是指针传递
//tableView刷新cel
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
//状态栏隐藏  NO显示
[UIApplication sharedApplication].statusBarHidden = YES;  
//隐藏navigationBar
self.navigationController.navigationBar.hidden = YES;
//有分隔符
//数组转字符串
NSString *string = [array componentsJoinedByString:@","];//,为分隔符
//字符串转数组
NSArray *array = [string componentsSeparatedByString:@","];
//无分隔符
NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
for (int i = 0; i < self.vin.length; i++) {
     NSRange range;
     range.location = i;
     range.length = 1;
     NSString *tempString = [self.vin substringWithRange:range];
     [array addObject:tempString];
 }
#pragma mark - 返回到指定界面
int index = (int)[[self.navigationController viewControllers]indexOfObject:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -2)]animated:YES];
if (self.navigationController.viewControllers.count >= 2) {
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1]animated:YES];
}

#pragma mark - 从自定义的view或cell跳转到控制器
//找到view所在的控制器
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

//通过找到的控制器进行跳转
- (void)TestButtonClick:(UIButton *)button {
    TestViewController *vc = [[TestViewController alloc]init] ;
    vc.hidesBottomBarWhenPushed = YES ;
    [[self viewController].navigationController pushViewController:vc animated:YES] ;
}

//获取当前屏幕显示的viewcontroller
UIViewController *result = [self getCurrentVC];
//必须使用present 方法
[result presentViewController:pick animated:YES completion:nil];

//获取当前屏幕显示的viewcontroller
- (UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    return result;
}
//发出通知
[[NSNotificationCenter defaultCenter] postNotificationName:@"WechatDidPayNotification" object:self userInfo:@{@"response":response}];

//接收通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WechatDidPayNotificationAction:) name:@"WechatDidPayNotification" object:nil];

//通知事件
- (void)WechatDidPayNotificationAction:(NSNotification *)notify{
    //移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"WechatDidPayNotification" object:nil];
    DLog(@"response = %@",notify.userInfo[@"response"]);
    PayResp *response = notify.userInfo[@"response"];
}

- (void)dealloc{
    //移除通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ConvenienceSubmitSuccessfulNFC" object:nil];
}

//移除所有监听
- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
//NSUserDefaults
[[NSUserDefaults standardUserDefaults] setObject:@"值" forKey:@"myPassword"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"myPassword"];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"myCookies"]) {
    NSURLRequest *request = [CookieCenter getCookie:@"myCookies" url:url];
    NSLog(@"request = %@",request);
    [_webView loadRequest:request];
} else {
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:3.0]];
}
//渐进式:边下载边显示
[imageView yy_setImageWithURL:url options:YYWebImageOptionProgressive]; 
//渐进式加载,增加模糊效果和渐变动画 (见本页最上方的GIF演示) 
[imageView yy_setImageWithURL:url options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
//按钮
[self.oneButton yy_setImageWithURL:[NSURL URLWithString:self.oneImageUrl] forState:UIControlStateNormal options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
[self.mainImageView yy_setImageWithURL:[NSURL URLWithString:model.pricture] placeholder:[UIImage imageNamed:PlaceholderGoodsFigure]];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342