[英]Image not loaded properly in uiimageView
请检查附件imageImage是否未正确加载到UIImageView
。
profileCell.currentMsgView.userPicImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",object.mediaPath]] placeholderImage:[UIImage imageNamed:@"defaultImage"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { }];
尝试通过设置内容模式,例如
profileCell.currentMsgView.userPicImageView.contentMode = UIViewContentModeScaleAspectFit;
并确保您设置了适当的约束。 如果您具有像元大小的图像视图,则您的约束应类似于: top,leading,trailing,bottom
这样可以解决问题。
试试这个简单的演示应用程序只是为了学习:-
ViewController.h代码在这里:-
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageOutput;
- (IBAction)btnOutput:(id)sender;
@end
ViewController.m代码在这里:-
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnOutput:(id)sender {
NSString *picUrl = @"http://cdn.wonderfulengineering.com/wp-content/uploads/2016/01/nature-wallpapers-9.jpg";
NSURL *theUrl = [NSURL URLWithString:picUrl];
NSData *imageData = [[NSData alloc]initWithContentsOfURL:theUrl];
_imageOutput.image = [UIImage imageWithData:imageData];
}
@end
用以下内容替换info.plist的整个代码,因为如果不这样做,您将无法访问“ http站点”,因为苹果出于安全原因会阻止http站点(为此,右键单击info.plist并作为源打开):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.