简体   繁体   English

图像未正确加载到uiimageView中

[英]Image not loaded properly in uiimageView

Please check attached imageImage 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) { }]; 

Try by setting content mode like, 尝试通过设置内容模式,例如

    profileCell.currentMsgView.userPicImageView.contentMode = UIViewContentModeScaleAspectFit;

And make sure that you have set proper constraints. 并确保您设置了适当的约束。 If you have imageview of cell's size then your constraints should be like : top,leading,trailing,bottom 如果您具有像元大小的图像视图,则您的约束应类似于: top,leading,trailing,bottom

This may solve the problem. 这样可以解决问题。

Try this simple demo app for just learning :- 试试这个简单的演示应用程序只是为了学习:-

ViewController.h code is here :- ViewController.h代码在这里:-

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageOutput;
- (IBAction)btnOutput:(id)sender;

@end

ViewController.m code is here :- 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

Replace whole code of info.plist with the following because without that you will not be able access "http site" because apple will block http site for security reason(for that right click on info.plist and open as source) :- 用以下内容替换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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM