我将UIWebView更改为WKWebView,但是,使用相同的html,WKWebView中的字体看起来比UIWebView中的字体要小.我不希望这种情况发生,所以有什么方法可以避免这种变化吗?
import 'package:flutter/material.dart';
class DraftPage extends StatefulWidget {
DraftPage({Key key}) : super(key: key);
@override
_DraftPageState createState() => _DraftPageState();
}
class _DraftPageState extends State<DraftPage> {
@override
Widget build(BuildContext context) {
final bottomTextStyle = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.red,
);
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Container(
alignment: Alignment.center,
width: 300,
height: 57,
decoration: BoxDecoration(
color: Colors.yellow,
),
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: 'AB',
style: bottomTextStyle,
),
TextSpan(
text: 'CD',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w500,
color: …Run Code Online (Sandbox Code Playgroud) 在 Swift 中,您可以轻松地将原始值分配给枚举,例如:
enum Game: Int {
case lol = 1
case dnf = 2
case dota = 3
}
Run Code Online (Sandbox Code Playgroud)
但是,您不能将原始值分配给 Dart 中的枚举:
enum Game {
lol = 1,
dnf = 2,
dota = 3,
}
Run Code Online (Sandbox Code Playgroud)
它显示错误,你只能使用最简单的枚举:
enum Game {
lol,
dnf,
dota,
}
Run Code Online (Sandbox Code Playgroud)
实在是让我很失望。
有什么办法可以像 Swift 一样将原始值分配给 Dart 的枚举吗?
我想用来NSTimer增加标签上显示的数字。
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(90, 90, 90, 30)];
[self.view addSubview:self.numberLabel];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(refreshText) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)refreshText{
NSDate *beginDate = [NSDate date];
static NSInteger a = 0;
a ++;
self.numberLabel.text = [NSString stringWithFormat:@"%ld",a];
if (a == 1000) {
NSDate *endDate = [NSDate date];
NSTimeInterval durationTime = [endDate timeIntervalSinceDate:beginDate];
NSTimeInterval intervalTime = self.timer.timeInterval; …Run Code Online (Sandbox Code Playgroud) Apple提供的反馈是:您的应用使用或引用了以下非公共API:
init:"App Store上不允许使用非公共API,因为如果这些API发生变化,可能会导致糟糕的用户体验.
让我最困惑的是"init:",我的意思是,"init:"有什么问题?我们不能使用"init:"?更重要的是,当我们使用非公共API时,Xcode会有什么变暖吗?我可以找到这些非公共API吗?
在我问这个问题之前,我试过了:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]];它在iOS8和iOS9上运行良好,但在iOS10上没有任何变化.[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];它在iOS8和iOS9上也能正常工作.但是,在iOS10上,当应用程序跳转到系统设置时,系统设置立即退出.[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];它在iOS8和iOS9上崩溃,同样,在iOS10上立即退出.问题是我们的应用程序可以跳转到iOS10上的系统设置吗?如果是的话.[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:nil];如何options?这意味着什么?我们必须为此代码options?
注意:我的问题是scrollView的方向会滚动,而不是滚动.也就是说,当用户滚动scrollView时,我们可以在scrollView开始滚动之前获取scrollView的方向滚动吗?
有什么想法吗?先谢谢.
我知道当我们使用块时,我们应该使用weakSelf来避免保留周期。但是我看到有时在块中有一个strongSelf。
让我感到困惑的是:
希望有人能给出一个确切的例子。
提前致谢。
为了这:
self.block = ^{
self.view.backgroundColor = [UIColor greenColor];
};
Run Code Online (Sandbox Code Playgroud)
显然有一个保留周期。
但是,有没有保留周期如果self是在typeof:
__weak typeof(self) weakSelf = self;
self.block = ^{
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.backgroundColor = [UIColor greenColor];
};
Run Code Online (Sandbox Code Playgroud)
自我的dealloc叫做即使self是在block.That手段块没有捕捉到self这里。
为什么?
我想从左到右布局单元格。所以我使用UICollectionViewFlowLayout:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// use this for let cell width fit for label width
layout.estimatedItemSize = CGSizeMake(80, 30);
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
Run Code Online (Sandbox Code Playgroud)
单元格的宽度适合标签的宽度:
// cell code
@implementation CQGoodsSearchCell
- (void)setupUI {
self.contentView.layer.cornerRadius = 15;
self.contentView.layer.masksToBounds = YES;
self.contentView.backgroundColor = [UIColor colorWithRed:1.00 green:1.00 blue:1.00 alpha:1.00];
self.nameLabel = [[UILabel alloc] init];
[self.contentView addSubview:self.nameLabel];
self.nameLabel.font = [UIFont systemFontOfSize:15];
self.nameLabel.textColor = [UIColor colorWithRed:0.18 green:0.18 blue:0.18 alpha:1.00];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(30);
make.top.bottom.mas_offset(0);
make.left.mas_offset(10);
make.right.mas_offset(-10);
}];
} …Run Code Online (Sandbox Code Playgroud) 我是 flutter 的新手,获取 StatefulWidget 状态的方式是向 widget 添加状态属性,例如:
// ignore: must_be_immutable
class _CustomContainer extends StatefulWidget {
_CustomContainer({Key key}) : super(key: key);
@override
__CustomContainerState createState() {
state = __CustomContainerState();
return state;
}
__CustomContainerState state;
void changeColor() {
if (state == null) return;
// call state's function
this.state.changeColor();
}
}
class __CustomContainerState extends State<_CustomContainer> {
var bgColor = Colors.red;
@override
Widget build(BuildContext context) {
return Container(
width: 200,
height: 200,
color: bgColor,
);
}
void changeColor() {
setState(() {
bgColor = Colors.blue;
}); …Run Code Online (Sandbox Code Playgroud) 有没有办法判断iPhone是iPhoneX系列(iPhone X XR XS XSmax)?
我的方式是:
#define iPhoneXSeries (([[UIApplication sharedApplication] statusBarFrame].size.height == 44.0f) ? (YES):(NO))
Run Code Online (Sandbox Code Playgroud)
有什么隐患吗?
还是有更好的方法吗?