我知道还有其他主题,但我似乎无法找到如何实现它.
我试图将UITextField限制为只有5个字符
优选字母数字和 - 和.和_
我见过这段代码
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange,
replacementString string: String) -> Bool
{
let maxLength = 4
let currentString: NSString = textField.text
let newString: NSString =
currentString.stringByReplacingCharactersInRange(range, withString: string)
return newString.length <= maxLength
}
Run Code Online (Sandbox Code Playgroud)
和
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
let length = count(textField.text.utf16) + count(string.utf16) - range.length
return length <= 10
}
Run Code Online (Sandbox Code Playgroud)
我只是不知道如何实际实现它或我应该换出哪个"textfield"我的自定义命名为UITextField
我正在使用Swift在Xcode(7.0版Beta)中创建一个游戏,我希望在游戏结尾以"gameOver.ttf"字体显示标签"Game Over".我已将字体添加到我的资源文件夹中.我不知道如何在我的代码中引用它.我能帮忙吗?我的代码:
let label = SKLabelNode(fontNamed: "gameOver")
label.text = "Game Over"
label.fontColor = SKColor.redColor()
label.fontSize = 150
label.position = CGPointMake(0, 100)
label.horizontalAlignmentMode = .Center
node.addChild(label)
Run Code Online (Sandbox Code Playgroud) 我有一个充满PHAsset对象的数组(https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/PHAsset_Class/index.html),我想知道如何将它们转换为UIImage然后将它们保存在一个数组中.
调用带有PHAsset对象的数组,self.assets这是我到目前为止所拥有的:
PHImageManager *manager = [PHImageManager defaultManager];
CGFloat scale = UIScreen.mainScreen.scale;
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[self.assets count]];
for (int i = 0; i < [self.assets count]; i++) {
CGSize targetSize = CGSizeMake(scale, scale);
[manager requestImageForAsset:[self.assets objectAtIndex:i]
targetSize:targetSize
contentMode:PHImageContentModeAspectFill
options:self.requestOptions
resultHandler:^(UIImage *image, NSDictionary *info){
[images addObject:image];
}];
}
Run Code Online (Sandbox Code Playgroud)
self.requestOptions是.h中的一个属性
@property (nonatomic, strong) PHImageRequestOptions *requestOptions;
Run Code Online (Sandbox Code Playgroud)
并在viewDidLoad我这样做:
self.requestOptions = [[PHImageRequestOptions alloc] init];
self.requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
self.requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
Run Code Online (Sandbox Code Playgroud)
但经过一些调试后,我一直看到它self.assets具有以下值:
(
<PHAsset: 0x1743828a0> 3B6D658D-EC76-43A1-9793-35D889E9CF15/L0/001 mediaType=1/0, assetSource=3, …Run Code Online (Sandbox Code Playgroud) 我正在实现自定义流布局.它有两种主要的覆盖方法来确定细胞的位置:layoutAttributesForElementsInRect和layoutAttributesForItemAtIndexPath.
在我的代码中,layoutAttributesForElementsInRect被称为,但layoutAttributesForItemAtIndexPath不是.什么决定了什么叫?layoutAttributesForItemAtIndexPath被叫哪里?
objective-c ios uicollectionview uicollectionviewlayout uicollectionviewdelegate
我有一个表视图,其中包含通过同一xib中的接口构建器创建的表头视图.我想根据屏幕大小设置标题的高度,例如屏幕高度的50%.
这是我在iPhone 4s上获得的静态高度:
这就是我在iPhone 6上得到的:

请注意,标头的内容是静态的.
我无法使用自动布局设置标题的约束.我试图根据表视图的高度设置高度约束,但在界面构建器中似乎不可能.控制拖动不起作用.我无法将标题从标题拖到表格视图甚至标题本身.

如何根据屏幕尺寸设置标题的高度?
我正在尝试实现一个循环指示器,随着值的变化,它会自动绘制动画.
我用CAShapeLayer画画动画.到目前为止,我每次都从头开始绘制它,它按预期工作.现在我想让它更圆滑并向前绘制并"擦除",具体取决于新值是否大于或低于之前的值.我不确定如何实现擦除部分.有一个背景所以我不能只用白色画在上面.这是一张图片,可以更好地了解它的外观.
有关如何实现擦除部分的任何想法?在类似的问题上有一些关于SO的解决方案,但那些涉及没有动画.
我使用此代码绘制:
- (void)drawCircleAnimatedWithStartAngle:(CGFloat)startAngle
endAngle:(CGFloat)endAngle
color:(UIColor *)color
radius:(int)radius
lineWidth:(int)lineWidth {
CAShapeLayer *circle = [CAShapeLayer layer];
circle.name = @"circleLayer";
circle.path = ([UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius-1 startAngle:startAngle endAngle:endAngle clockwise:YES].CGPath);
// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor colorWithRed:19.0/255 green:167.0/255 blue:191.0/255 alpha:1].CGColor;
circle.lineWidth = lineWidth;
// Add to parent layer
for (CALayer *layer in self.circleView.layer.sublayers) {
if ([layer.name isEqualToString:@"circleLayer"]) {
[layer removeFromSuperlayer];
break;
}
}
[self.circleView.layer addSublayer:circle];
circle.zPosition = 1;
// Configure animation …Run Code Online (Sandbox Code Playgroud) AFNetworking的缓存机制对我不起作用,我有500ko的大尺寸图像,我想缓存它.但每次我关闭应用程序并再次打开它时,我必须等待20秒才能加载图像,因此缓存系统不能正常运行,代码如下:
我试过了 :
[imageView setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
Run Code Online (Sandbox Code Playgroud)
然后尝试:
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
[imageView setImageWithURLRequest:imageRequest
placeholderImage:[UIImage imageNamed:@"placeholder"]
success:nil
failure:nil];
Run Code Online (Sandbox Code Playgroud) 我一直试图监控卸载的数量,但找不到可靠的方法.
后来我检查了AppsFlyer提供此功能来跟踪卸载次数.
任何人都可以解释AppsFlyer卸载跟踪的可靠性和原因吗?
我在导航项目上使用UISearchController(导航栏已设置为使用barTintColor和tintColor)。关闭搜索控制器后(点击搜索栏的“取消”按钮),后退按钮的tintColor将恢复为默认值(蓝色)。
屏幕截图2:当UISearchController处于活动状态时:

屏幕快照3:关闭UISearchController时(通过点击“取消”),您会看到“后退”按钮的tintColor恢复为默认值(蓝色),而不是白色:

屏幕截图上的代码是:
/// View controller is embedded in a UINavigationController, the root view controller of the startup storyboard.
class ViewController: UIViewController {
lazy var searchController: UISearchController = {
let controller = UISearchController(searchResultsController: nil)
controller.searchBar.tintColor = .white
return controller
}()
override func viewDidLoad() {
super.viewDidLoad()
if let navigationBar = navigationController?.navigationBar {
setupNavigationBar(navigationBar)
}
if #available(iOS 11.0, *) {
navigationItem.searchController = searchController
} else {
navigationItem.titleView = searchController.searchBar
}
}
func setupNavigationBar(
_ navigationBar: UINavigationBar,
barTintColor: UIColor = …Run Code Online (Sandbox Code Playgroud) ios ×8
objective-c ×4
swift ×2
animation ×1
app-store ×1
appsflyer ×1
arrays ×1
autolayout ×1
caching ×1
cashapelayer ×1
character ×1
drawing ×1
fonts ×1
ios13 ×1
iphone ×1
string ×1
tintcolor ×1
uiimage ×1
uitableview ×1
uitextfield ×1
xcode ×1