小编kb9*_*920的帖子

在UIImageView中获取图像的大小

在以编程方式将图像分配给UIImageView之后,我无法获取图像的大小。

下面的代码循环运行,并使用函数(getNoteImage)从URL(photoURL)下载图像并将其分配给创建的UIImageView。我需要获取图像的高度,以便可以计算以下图像和标签的间距。

        var myImage :UIImageView

        myImage = UIImageView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))

        myImage.center = CGPointMake(UIScreen.mainScreen().bounds.size.width/2, imageY)

        myImage.getNoteImage(photoUrl)

        self.detailsView.addSubview(myImage)

        myImage.contentMode = UIViewContentMode.ScaleAspectFit

        imageHeight = myImage.bounds.size.height
Run Code Online (Sandbox Code Playgroud)

我尝试使用

imageHeight = myImage.bounds.size.height
Run Code Online (Sandbox Code Playgroud)

我在另一篇文章中将其作为解决方案来阅读,但他只是返回设备的屏幕尺寸(iPhone6模拟器上为667)。

谁能指导我如何获得正确的图像尺寸?谢谢

uiimageview uiimage ios swift swift2

2
推荐指数
1
解决办法
3695
查看次数

iOS 10通知内容扩展未加载

我有一个简单的应用程序来播放推送通知.我有通知服务扩展工作.我可以使用图片URL发送远程通知并加载它.

我似乎无法让Notification Content Extension工作.我已经完成了多个教程,他们都说,只需从目标菜单创建一个Notification Content Extension,然后在Notification Content Extensions Info.plist中设置

UNNotificationCategory
Run Code Online (Sandbox Code Playgroud)

一些字符串.然后当您按下通知时,在"aps"json-block内部确保类别与UNNotificationCategory相同.

当我收到通知时,我会尝试向左或向右滑动它,并且没有任何实际发生.但是,服务扩展正在发挥作用.

我正在使用带有ios10和xCode 8.0的iPhone 5.我读到,只有具有3d touch的设备才可以查看内容扩展,但是自从改变了以后xCode 8已经超出测试版.

有任何想法吗?我该如何调试呢?我已经尝试选择通知扩展程序运行应用程序并打印出内部的东西

didReceive
Run Code Online (Sandbox Code Playgroud)

但我没有运气.

push-notification apple-push-notifications swift ios10 unnotificationrequest

2
推荐指数
3
解决办法
3663
查看次数

在捏手势中增加字体大小

我有一个UILabel,其字体大小将增加捏手势iOS swift.我能够增加字体大小,但视图有问题.思想sizeToFit()根据需要增加高度和宽度,但它不会反映在视图上,即标签在视图中保持不变.随着字体大小的增加,请帮我增加标签的大小.

 @IBAction func increaseTextFont(sender: UIPinchGestureRecognizer) {
        var pinchScale = sender.scale
        pinchScale = round(pinchScale * 1000) / 1000.0

        if (pinchScale < 1) {
            testLabel.font = UIFont( name: "arial", size: testLabel.font.pointSize - pinchScale)
        }
        else{
            testLabel.font = UIFont( name: "arial", size: testLabel.font.pointSize + pinchScale)
        }
testLabel.frame.height * pinchScale))
        testLabel.frame.size.height *= pinchScale
        testLabel.frame.size.width *= pinchScale
        self.testLabel.layoutIfNeeded()
        print(testLabel.frame.size.height)
        print(testLabel.frame.size.width)

    }
Run Code Online (Sandbox Code Playgroud)

uilabel ios swift

1
推荐指数
1
解决办法
1544
查看次数

右对齐UISearchbar占位符

该代码曾经可以工作,但是在ios 10之后,它已停止运行:

UITextField *searchTextField = [_searchBar valueForKey:@"_searchField"];
searchTextField.textAlignment = NSTextAlignmentRight
Run Code Online (Sandbox Code Playgroud)

我已经尝试了段落和attributedPlaceholder,但占位符始终保持对齐。该错误出现在xcode 7和8中。如何解决此问题?

iphone objective-c uisearchbar ios ios10

1
推荐指数
1
解决办法
1046
查看次数

如何在Objective C中比较日期格式的字符串

我有两个格式为Fri的字符串,2016年1月22日10:46:50 +0530.我需要比较这两个字符串.如果可以通过将它们转换为日期来完成,我该如何编写NSDateFormatter样式.试过下面的代码.但没有工作.我将newDate和currentDate设为nil.任何帮助,将不胜感激.

NSString *dateString1 = @"Fri, 22 Jan 2016 10:46:50 +0530";
NSString *dateString2 = @"Fri, 21 Jan 2016 10:46:50 +0530";
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateStyle:NSDateFormatterFullStyle];

NSDate *newDate = [inputFormatter dateFromString:dateString1];
NSDate *currentDate = [inputFormatter dateFromString:dateString2];

[inputFormatter release];

NSComparisonResult result = [newDate compare:currentDate]; // comparing two dates

if(result == NSOrderedAscending || result == NSOrderedSame) {
    NSLog(@"newDate is less or same");
}
Run Code Online (Sandbox Code Playgroud)

objective-c nsdateformatter ios

0
推荐指数
1
解决办法
1095
查看次数