uiimageview

Save struct in class to NSUserDefaults using Swift

蓝咒 提交于 2019-12-18 12:29:45
问题 I have a class and inside the class is a (swift) array, based on a global struct. I want to save an array with this class to NSUserDefaults. This is my code: struct mystruct { var start : NSDate = NSDate() var stop : NSDate = NSDate() } class MyClass : NSObject { var mystructs : [mystruct] init(mystructs : [mystruct]) { self.mystructs = mystructs super.init() } func encodeWithCoder(encoder: NSCoder) { //let val = mystructs.map { $0 as NSObject } //this also doesn't work let objctvtmrec =

How to check if a NSData is valid for usage in UIImage

五迷三道 提交于 2019-12-18 12:24:32
问题 NSError *error = nil; NSURL *url = [NSURL URLWithString:[imageLinks objectAtIndex:0]]; NSData *tdata = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error]; if (error) { NSLog(@"%@", [error localizedDescription]); }else { // no error, this one is being called within my app NSLog(@"Data loaded successfully"); } self.pictureView1.image = [UIImage imageWithData:tdata]; I have a jpeg file, I can confirm that the URL content is gathered successfully, but when I try to put

UIEdgeInsetsMake creating a weird band on the cell, and I don't know how to fix it

时光毁灭记忆、已成空白 提交于 2019-12-18 11:57:30
问题 I'm trying to use UIEdgeInsetsMake to make set the background of my cell to a gradient. I've tried multiple things to get it to work, but no matter what I use, there's always an issue. I simply have two static cells, where I'm trying to set their backgroundView in willDisplayCell: . I have separate images for the top, bottom and middle cells, but since I have two cells I only need the top and the bottom. These are those images: Top Bottom There's a missing line on the top of the bottom one so

UIEdgeInsetsMake creating a weird band on the cell, and I don't know how to fix it

随声附和 提交于 2019-12-18 11:57:12
问题 I'm trying to use UIEdgeInsetsMake to make set the background of my cell to a gradient. I've tried multiple things to get it to work, but no matter what I use, there's always an issue. I simply have two static cells, where I'm trying to set their backgroundView in willDisplayCell: . I have separate images for the top, bottom and middle cells, but since I have two cells I only need the top and the bottom. These are those images: Top Bottom There's a missing line on the top of the bottom one so

UIScrollView phantom subviews

元气小坏坏 提交于 2019-12-18 11:53:07
问题 I am loading a view from a nib file using: NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"AnalysisView" owner:self options:nil]; AnalysisView *gridView = [nibViews objectAtIndex: 0]; The nib contains a scrollview called gridScrollView and in the AnalysisView implementation file I have a method which adds views as subviews to the scrollview: for (NSInteger i = [results count] -1; i >= 0; i--) { Result *result = [results objectAtIndex:i]; [self loadResult: result]; } - (void)

UIScrollView phantom subviews

风格不统一 提交于 2019-12-18 11:52:16
问题 I am loading a view from a nib file using: NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"AnalysisView" owner:self options:nil]; AnalysisView *gridView = [nibViews objectAtIndex: 0]; The nib contains a scrollview called gridScrollView and in the AnalysisView implementation file I have a method which adds views as subviews to the scrollview: for (NSInteger i = [results count] -1; i >= 0; i--) { Result *result = [results objectAtIndex:i]; [self loadResult: result]; } - (void)

How to blur an existing image in a UIImageView with Swift?

风流意气都作罢 提交于 2019-12-18 11:47:45
问题 The setup is simple. A ViewController with UIImageView that has an image assigned. A UIButton that when clicked blurs the image in the UIImageView. import UIKit class ViewController: UIViewController { @IBOutlet weak var bg: UIImageView! @IBAction func blur(_ sender: Any) { let inputImage = CIImage(cgImage: (bg.image?.cgImage)!) let filter = CIFilter(name: "CIGaussianBlur") filter?.setValue(inputImage, forKey: "inputImage") filter?.setValue(10, forKey: "inputRadius") let blurred = filter?

Converting Text to Image on iOS

半城伤御伤魂 提交于 2019-12-18 11:36:03
问题 How to convert Text to Image and show in UIImageview. Can anyone know the conversion from Text to Image? 回答1: You can start playing around with something like this: NSString *string = @"Some text"; UIGraphicsBeginImageContext(CGSizeMake(80, 50)); [string drawAtPoint:CGPointMake(10, 20) withFont:[UIFont systemFontOfSize:12]]; UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); result contains the UIImage with the text in it, and you can assign it to the

Get image file type programmatically in swift

好久不见. 提交于 2019-12-18 10:56:35
问题 I am downloading images from parse with file totes PNG and JPEG. When image is downloaded to the app I need to determine what the file type is so I can handle image accordingly. Had a look at API for uiimageview and did a search but can't find any solution in swift. Any input appreciated Trying to get url from PFFIle §: let imageURLFromParse = NSURL(string : caseImageFile2.url); // Error here: 'NSURL?' does not have a member named 'pathExtension' if(imageURLFromParse.pathExtension!

Capture UIView as UIImage

一笑奈何 提交于 2019-12-18 10:38:13
问题 I have been using this method to convert a UIView into UIImage . i.e. screen snapshot of a view - @interface UIView(Extended) - (UIImage *) imageByRenderingView; @end @implementation UIView(Extended) - (UIImage *)imageByRenderingView { UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return resultingImage; } @end To use it, I do this -