let timeZone = NSTimeZone.system.description
let localTimeZone = TimeZone.ReferenceType.local.description
let currentTimeZone = TimeZone.current.description
let defaultTimeZone = TimeZone.ReferenceType.default.description
let autoUpdateTimezon = TimeZone.autoupdatingCurrent.description
print ("System Timezone \(timeZone)")
print ("Local Timezone \(localTimeZone)")
print ("Current Timezone \(currentTimeZone)")
print ("Default Timezone \(defaultTimeZone)")
print ("Auto updating Timezone \(autoUpdateTimezon)")
Run Code Online (Sandbox Code Playgroud)
输出
亚洲系统时区/加尔各答(当前)
本地时区亚洲/加尔各答(自动更新当前)
当前时区亚洲/加尔各答(当前)
默认时区亚洲/加尔各答(当前)
自动更新时区亚洲/加尔各答 (autoupdatingCurrent)
所以,我得到所有的输出都是一样的,所以这些时区之间有什么区别,在这种情况下我们应该使用哪个时区。
问题
我使用以下代码进行日期转换
static func stringToString(strDate:String, fromFormat:String, toFormat:String)->String{
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.init(abbreviation: "UTC") ?? TimeZone(identifier: "UTC") ?? TimeZone.ReferenceType.default
dateFormatter.dateFormat = fromFormat
let currentDate = dateFormatter.date(from: strDate) ?? Date()
dateFormatter.dateFormat …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个支持两种语言的应用程序,即英语和阿拉伯语。我几乎完成了所有任务,即在应用程序中本地化+处理UI LTR(英语),RTL(阿拉伯语)。
现在,我想在情节提要中查看RTL中的UI预览。默认情况下为LTR。
到目前为止,我所做的是:
+(void)initialize {
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString *current = [languages objectAtIndex:0];
[self setLanguage:current];
Run Code Online (Sandbox Code Playgroud)
}
+(void)setLanguage:(NSString *)l {
NSLog(@"\n\n\t ***** Hint Lang. selected by user: %@ ****\n\n", l);
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
bundle = [NSBundle bundleWithPath:path];
Run Code Online (Sandbox Code Playgroud)
}
+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
return [bundle localizedStringForKey:key value:alternate table:nil];;
Run Code Online (Sandbox Code Playgroud)
}
用于处理UI LTR或RTL。例如,当用户选择英语时,我将UI设置为
[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
Run Code Online (Sandbox Code Playgroud)
当用户选择阿拉伯语时,我将UI设置为
[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
Run Code Online (Sandbox Code Playgroud)
但是我必须检查所有内容,然后运行应用程序iPhone UI屏幕,无论对于LTR还是RTL都适用。
有什么方法可以让我们在情节提要中以RTL形式查看预览UI(无需在iPhone /模拟器中运行)。任何建议都会很棒!提前致谢!!
是否有必要强制使用自动布局来仅使用 stackview 假设我已经制作了没有自动布局的整个项目,现在对于特定屏幕我必须使用 Stackview 来平均划分视图内的标签数量。有什么解决办法吗..
问题
实际上我必须自定义一个没有自动布局的旧项目,现在我必须只修改一个屏幕,它不需要任何约束,而只是像 uitablecell 一样的 stackview,每个单元格中有 8 个标签等分。
我知道我们可以通过计算帧运行时间来做到这一点,但是还有其他方法可以做到吗?
我想无限地以编程方式快速滚动collectionView中的10张图像。图片是根据我的选择来自json的网络。我一直无法滚动20张图像。这是我的代码
import Foundation
import UIKit
let categoryCellid = "categoryCellid"
class ProductByCategoryCollectionView: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var headercellId = "headercellId"
var callCategoryObject = [Product]()
func getPropductListByCategory(){
// has api code, that was well
}
override func viewDidLoad() {
super.viewDidLoad()
self.getPropductListByCategory()
collectionView?.backgroundColor = .white
navigationItem.title = "Product"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Sort By", style: .plain, target: nil, action: nil)
self.setupHeaderView()
collectionView?.register(ProductByCategoryCollectionViewCell.self, forCellWithReuseIdentifier: categoryCellid)
}
func showCategoryDetailSegue() {
let detailcontroller = UIViewController()
navigationController?.pushViewController(detailcontroller, animated: true) …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个应用程序,如果您第一次打开应用程序,并且如果您在任何其他时间打开应用程序,则按钮会将您带到配置文件注册表视图.如何以编程方式完成此操作,我看到的所有内容只将按钮连接到一个视图.
@IBAction func NextViewController(_ sender: UIButton) {
if launchedBefore {
print("Not first launch.")
} else {
print("First launch, setting UserDefault.")
UserDefaults.standard.set(true, forKey: "launchedBefore")
}
}
Run Code Online (Sandbox Code Playgroud) 如何快速获得 UITabBar 项目的选定索引我不是在谈论UITabBarController。
我知道我可以使用 UITabBarItem.tag。
但对我来说,我不能为选定的索引使用标签,因为它已经用于其他目的。有没有其他方法可以快速获取所选选项卡的索引。
ios ×6
swift ×5
swift3 ×2
autoresize ×1
datetime ×1
infinite ×1
iphone ×1
localization ×1
nstimezone ×1
objective-c ×1
scroll ×1
stackview ×1
storyboard ×1
timezone ×1
xcode ×1