[英]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.