小笔记

//修改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 *)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]];

你可能感兴趣的:(小笔记)