uiimageview

How do I autoresize an image, but at the top of the ImageView (programmatically in Xcode)?

走远了吗. 提交于 2019-12-24 08:59:08
问题 I have an imageView (say 100x100) that I want to fill with a (smaller) image (say 50x10) and I want the image to go at the top of the view , not at the middle of the view. If I use imageView.contentMode = UIViewContentModeScaleAspectFit; it fills the view with the image scaled at 100x20 (as expected) but in the middle of the view. Like this: +---------+ | | |i m a g e| <---my image (scaled) | | +---------+ <---my UIImageView If I set imageView.contentMode = UIViewContentModeTop |

IOS UIImageView displays with black background

家住魔仙堡 提交于 2019-12-24 08:49:40
问题 So I've got this function that scales UIImages , and I'm using it to initialise a UIImageView with an image. My problem is that the when the image is displayed, it always has a black rectangle around it, despite the image being a .png with full transparency in the background. Here is the scaling method as well as the initialisation of the UIImageView : - (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {

Save a UIImage and reused it on UIImageview

那年仲夏 提交于 2019-12-24 08:38:37
问题 I currently have the ability to take a photo or load from the camera and place an image in the UIImageView in my app be i want the ability to have a button that will save the image so when i reload the app the image is still in the UIImageView. My though was a button to save the image once you have loaded it and in the -(void)viewDidLoad have the code to load the image that was saved but i don't know how to approach this. Any help would be fantastic. 回答1: You can convert images to NSData

SDWebImage doesn't work

99封情书 提交于 2019-12-24 07:57:49
问题 What am I doing wrong? Everything runs but I don't get the Images, help! Thanks! import UIKit import Firebase import FirebaseDatabase import SDWebImage struct postStruct { let title : String! let downloadURL : String! } class ZeroHomeViewController: UITableViewController { var posts = [postStruct]() override func viewDidLoad() { super.viewDidLoad() let ref = Database.database().reference().child("Posts") ref.observeSingleEvent(of: .value, with: { snapshot in print(snapshot.childrenCount) for

NSCoding Persisting UIImage

半世苍凉 提交于 2019-12-24 07:36:05
问题 I have seen different question on stackoverflow related to this topic. Some says that NSCoding does not conform with UIImage and other says that with iOS 5, it does conform. I want to persist images in my app. I am using encode and decode methods and everything (title, labels etc) are persisting but NOT the images. - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:title forKey:@"title"]; [aCoder encodeObject:link forKey:@"link"]; [aCoder encodeObject:creator forKey:@"creator"];

How to change the label text in UIScrollview for each page Different text?

…衆ロ難τιáo~ 提交于 2019-12-24 06:44:55
问题 Hi in my app i want to show label text different at each image in UIScrollView. Here is my code. for (int i=0; i<imageArray.count; i++) { NSString *str = [imageArray objectAtIndex:i]; NSString *bannerImageURL = [NSString stringWithFormat:@"http://url.com", str]; CGFloat myOrigin = i * self.view.frame.size.width; UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(myOrigin, 0, self.view.frame.size.width,imgScrollView.frame.size.height)]; myImageView.contentMode =

Archiving UIImageView with NSCoding

半世苍凉 提交于 2019-12-24 06:38:47
问题 I've never used NSCoding before and I'm very confused about how it should be implemented. My current iPad app has a UIImageView (called "background") which is a property of my main view controller. "background" has a UIImage "image" property (obviously) and various subviews which are added by the user. The added subviews are my own custom subclasses of UIImageView. I need to be able to save the state of the "background" UIImageView so it can be restored with the same image and all the

How to stretch image into custom shape (swift3)

拈花ヽ惹草 提交于 2019-12-24 04:36:06
问题 The code list below crops the image. I would like the image to be transformed/ stretched and not cropped in the shape. All of the image contents are still in the transformed picture. It will just look different. extension UIImageView { func addMask(_ bezierPath: UIBezierPath) { let pathMask = CAShapeLayer() pathMask.path = bezierPath.cgPath layer.mask = pathMask } } let myPicture = UIImage(data: try! Data(contentsOf: URL(string:"https://scontent-iad3-1.xx.fbcdn.net/v/t31.0-8/14196150

How do I resize a picture using UIImageView so that I can zoom in and out?

柔情痞子 提交于 2019-12-24 03:47:09
问题 In my view I have a picture.. The picture has a 3:2 scale and is huge, resolution wise. I'm having a lot of trouble initializing a UIImage with the image to the original size and then zooming out of the UIImageView so that the entire image is visible within the scrollview. The program stays only in the portrait orientation. And no, please don't say to just use UIWebView. UIWebView doesn't let me set the content size during view load...instead, it just zooms out of the image by some arbitrary

AFNetworking 2.0 setImageWithURLRequest

故事扮演 提交于 2019-12-24 03:19:20
问题 I'm using this code when downloading images in one of my current projects and it's not working with AFNetworking 2.0. I tried going thru AFImageResponseSerializer but I can't find the right code to use. [cell.posterImage setImageWithURLRequest:urlRequest placeholderImage:[UIImage imageNamed:@"placeholder.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { cell.posterImage.image = image; } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError