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