小筆記

//修改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加載頁面后會發(fā)現(xiàn)頁面的字會很小, 這是因?yàn)樵W(wǎng)頁沒有做手機(jī)屏幕尺寸的適配, 那么在后臺不做調(diào)整的情況下我們移動端怎樣來適配頁面
_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;
//屏幕點(diǎn)擊事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSLog(@"點(diǎn)擊了屏幕");
}
//判斷是否為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;
}
//數(shù)組循環(huán)刪除元素
//逆序遍歷
for (WearingPartsSpecialAttributesHeaderModel *headerModel in [self.headerDataArray reverseObjectEnumerator]) {
  if ([headerModel.name isEqualToString:@"配件品牌"]) {
      [self.headerDataArray removeObject:headerModel];
   }
}
#pragma mark - 重置導(dǎo)航
- (void)resetNav{
   self.titleLabel.text = @"發(fā)票管理";
   [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 - 按鈕響應(yīng)方法
- (void)backButtonClick{
    DLog(@"返回");
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)submitButtonClick{
    DLog(@"添加");
}
//按鈕防重點(diǎn)
addButton.timeInterval = 2;
//純數(shù)字鍵盤:
textField.keyboardType = UIKeyboardTypeNumberPad;
//純數(shù)字加小數(shù)點(diǎn)鍵盤:
textField.keyboardType = UIKeyboardTypeDecimalPad;
//設(shè)置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
//原因:創(chuàng)建block的時候官硝,已經(jīng)把a(bǔ)ge的值存儲在里面了府蔗。

auto int age = 10;
static int num = 25;
void (^Block)(void) = ^{
    NSLog(@"age:%d,num:%d",age,num);
};
age = 20;
num = 11;
Block();
//輸出結(jié)果為: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];
//狀態(tài)欄隱藏  NO顯示
[UIApplication sharedApplication].statusBarHidden = YES;  
//隱藏navigationBar
self.navigationController.navigationBar.hidden = YES;
//有分隔符
//數(shù)組轉(zhuǎn)字符串
NSString *string = [array componentsJoinedByString:@","];//,為分隔符
//字符串轉(zhuǎn)數(shù)組
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跳轉(zhuǎn)到控制器
//找到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;
}

//通過找到的控制器進(jìn)行跳轉(zhuǎn)
- (void)TestButtonClick:(UIButton *)button {
    TestViewController *vc = [[TestViewController alloc]init] ;
    vc.hidesBottomBarWhenPushed = YES ;
    [[self viewController].navigationController pushViewController:vc animated:YES] ;
}

//獲取當(dāng)前屏幕顯示的viewcontroller
UIViewController *result = [self getCurrentVC];
//必須使用present 方法
[result presentViewController:pick animated:YES completion:nil];

//獲取當(dāng)前屏幕顯示的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;
}
//發(fā)出通知
[[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];
}

//移除所有監(jiān)聽
- (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]];
}
//漸進(jìn)式:邊下載邊顯示
[imageView yy_setImageWithURL:url options:YYWebImageOptionProgressive]; 
//漸進(jìn)式加載,增加模糊效果和漸變動畫 (見本頁最上方的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]];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖凳怨,帶你破解...
    沈念sama閱讀 219,490評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異是鬼,居然都是意外死亡肤舞,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評論 3 395
  • 文/潘曉璐 我一進(jìn)店門均蜜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來李剖,“玉大人,你說我怎么就攤上這事囤耳「菟常” “怎么了偶芍?”我有些...
    開封第一講書人閱讀 165,830評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長德玫。 經(jīng)常有香客問我匪蟀,道長,這世上最難降的妖魔是什么宰僧? 我笑而不...
    開封第一講書人閱讀 58,957評論 1 295
  • 正文 為了忘掉前任材彪,我火速辦了婚禮,結(jié)果婚禮上琴儿,老公的妹妹穿的比我還像新娘段化。我一直安慰自己,他們只是感情好造成,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評論 6 393
  • 文/花漫 我一把揭開白布显熏。 她就那樣靜靜地躺著,像睡著了一般晒屎。 火紅的嫁衣襯著肌膚如雪喘蟆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,754評論 1 307
  • 那天夷磕,我揣著相機(jī)與錄音,去河邊找鬼仔沿。 笑死坐桩,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的封锉。 我是一名探鬼主播绵跷,決...
    沈念sama閱讀 40,464評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼成福!你這毒婦竟也來了碾局?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤奴艾,失蹤者是張志新(化名)和其女友劉穎净当,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蕴潦,經(jīng)...
    沈念sama閱讀 45,847評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡像啼,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了潭苞。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片忽冻。...
    茶點(diǎn)故事閱讀 40,137評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖此疹,靈堂內(nèi)的尸體忽然破棺而出僧诚,到底是詐尸還是另有隱情遮婶,我是刑警寧澤,帶...
    沈念sama閱讀 35,819評論 5 346
  • 正文 年R本政府宣布湖笨,位于F島的核電站旗扑,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏赶么。R本人自食惡果不足惜肩豁,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望辫呻。 院中可真熱鬧清钥,春花似錦、人聲如沸放闺。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽怖侦。三九已至篡悟,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間匾寝,已是汗流浹背搬葬。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留艳悔,地道東北人急凰。 一個月前我還...
    沈念sama閱讀 48,409評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像猜年,于是被迫代替她去往敵國和親抡锈。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評論 2 355