Questions tagged «ios»

iOS是在Apple iPhone,iPod touch和iPad上运行的移动操作系统。使用此标签[ios]来解决与iOS平台上的编程有关的问题。使用相关的标签[objective-c]和[swift]解决那些编程语言所特有的问题。


11
iOS:如何从数字中获取正确的月份名称?
我知道NSDateformatter功能套件对人类来说是一个福音,但与此同时,这也让我感到困惑。我希望你能帮助我。 在我的代码中的某个地方,有一个int代表一个月。因此:1是1月,2月2日,依此类推。 在我的用户界面中,我想将此整数显示为正确的月份名称。此外,它应遵守设备的语言环境。 谢谢您的见解 同时,我已经完成了以下工作: int monthNumber = 11 NSString * dateString = [NSString stringWithFormat: @"%d", monthNumber]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM"]; NSDate* myDate = [dateFormatter dateFromString:dateString]; [dateFormatter release]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MMMM"]; NSString *stringFromDate = [formatter stringFromDate:myDate]; [formatter release]; 这是这样做的方法吗?似乎有点罗word。


15
分页UIScrollView的增量小于帧大小
我有一个滚动视图,它是屏幕的宽度,但只有大约70像素高。它包含许多我希望用户可以选择的50 x 50图标(周围带有空格)。但是我始终希望滚动视图以分页的方式运行,始终以图标居中停止。 如果图标是屏幕的宽度,那将不是问题,因为UIScrollView的分页会处理它。但是因为我的小图标远远小于内容大小,所以它不起作用。 我之前在应用程序AllRecipes中已经看到了这种行为。我只是不知道该怎么做。 如何按图标大小进行分页工作?


10
在2017年使用IBDesignable绘制点划线(而不是虚线!)
使用UIKit绘制虚线很容易。所以: CGFloat dashes[] = {4, 2}; [path setLineDash:dashes count:2 phase:0]; [path stroke]; 有没有办法画出真实的虚线? 有任何想法吗? 由于此问题确实存在很久,并且没有人提出完整的@IBDesignable解决方案,因此这里是... 希望它可以节省一些键入的时间。 @IBDesignable class DottedVertical: UIView { @IBInspectable var dotColor: UIColor = UIColor.etc @IBInspectable var lowerHalfOnly: Bool = false override func draw(_ rect: CGRect) { // say you want 8 dots, with perfect fenceposting: let totalCount …
86 ios  swift  uiview  uikit 

7
在iOS上发送HTTP POST请求
我正在尝试使用正在开发的iOS应用程序发送HTTP Post,但尽管我确实得到了响应200(来自urlconnection)作为响应,但推送从未到达服务器。我从服务器未收到响应,服务器也未检测到我的帖子(服务器确实检测到来自Android的帖子) 我确实使用ARC,但已将pd和urlConnection设置为强。 这是我发送请求的代码 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",dk.baseURL,@"daantest"]]]; [request setHTTPMethod:@"POST"]; [request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"]; NSString *sendString = @"<data><item>Item 1</item><item>Item 2</item></data>"; [request setValue:[NSString stringWithFormat:@"%d", [sendString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[sendString dataUsingEncoding:NSUTF8StringEncoding]]; PushDelegate *pushd = [[PushDelegate alloc] init]; pd = pushd; urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:pd]; [urlConnection start]; 这是我给代表的代码 …

6
在没有推送通知的情况下更新iOS徽章
我看到一些待办事项应用程序会在午夜更新其应用程序徽章,并始终显示正确数量的到期任务。他们无需使用推送通知即可执行此操作-所以我的问题是:他们如何做到这一点?他们是否使用本地通知-如果这样,则在设备关闭时会被调用吗?我有些困惑,不胜感激。

8
ActionSheet无法使用iPad
我在应用程序中使用ActionSheet。在我的iPhone上可以运行,但在iPad模拟器上却不能。 这是我的代码: @IBAction func dialog(sender: AnyObject) { let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .ActionSheet) let deleteAction = UIAlertAction(title: "Delete", style: .Default, handler: { (alert: UIAlertAction!) -> Void in println("Filtre Deleted") }) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { (alert: UIAlertAction!) -> Void in println("Cancelled") }) …

3
Xcode 8中的“因性而异”是什么?
我正在使用AutoLayout和Size类,但是随着iOS 10和新Xcode 8.0的发布,有一个新选项Vary for Traits。是否针对不同宽度和高度的设备替换了尺寸分类。 通过选中width复选框,将显示varying 14 compact width devices。 通过选中height复选框,将显示varying 18 compact height devices。 通过选中两个复选框,将显示varying 11 compact width regular height devices。 如何利用此选项?我们可以将AutoLayout与Xcode7.0之类的大小类一起使用吗?如果任何人有深入的知识,请解释。

6
标题中包含两行文本的UIButton(numberOfLines = 2)
我正在尝试使UIButtontitleLabel中包含两行文本。这是我正在使用的代码: UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)]; titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:24.0]; [titleButton setTitle:@"This text is very long and should get truncated at the end of the second line" forState:UIControlStateNormal]; titleButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; titleButton.titleLabel.numberOfLines = 2; [self addSubview:titleButton]; 当我尝试此操作时,文本仅显示在一行上。似乎要获得多行文本的唯一方法UIButton.titleLabel是设置numberOfLines=0和使用UILineBreakModeWordWrap。但这不能保证文本恰好是两行。 UILabel但是,使用纯文本确实可以: UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, …

5
如何在Swift中为UIBarButtonItem设置操作
如何在Swift中设置自定义UIBarButtonItem的操作? 以下代码将按钮成功放置在导航栏中: var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:nil) self.navigationItem.rightBarButtonItem = b 现在,我想func sayHello() { println("Hello") }在触摸按钮时打电话。到目前为止,我的努力: var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:sayHello:) // also with `sayHello` `sayHello()`, and `sayHello():` 和.. var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:@selector(sayHello:)) // also …

9
在Swift枚举期间从数组中删除?
我想枚举Swift中的数组,并删除某些项目。我想知道这样做是否安全,如果不能,我应该如何实现这一目标。 目前,我会这样做: for (index, aString: String) in enumerate(array) { //Some of the strings... array.removeAtIndex(index) }

7
@IBInspectable与枚举?
我想创建@IBInspectable元素,如下图所示: 我的想法是使用像enum这样的类型作为类型@IBInspectable,但是看起来并非如此,有什么想法如何实现这样的元素? 编辑: 看起来@IBInspectable仅支持以下类型: Int CGFloat Double String Bool CGPoint CGSize CGRect UIColor UIImage 笨蛋

18
在UINavigationController中隐藏导航栏时不向后滑动
我喜欢从将您的视图嵌入到NET中继承的滑动包UINavigationController。不幸的是,我似乎找不到隐藏它的方法,NavigationBar但仍然可以向后滑动触摸板gesture。我可以编写自定义手势,但我不希望这样做,而是依靠UINavigationController向后滑动gesture。 如果我在情节提要图中取消选中,则后向滑动不起作用 或者,如果我以编程方式将其隐藏,则采用相同的方案。 - (void)viewDidLoad { [super viewDidLoad]; [self.navigationController setNavigationBarHidden:YES animated:NO]; // and animated:YES } 有没有办法隐藏顶部NavigationBar并仍然可以滑动?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.