[英]Adjust UIImageView width according to height
我有數百個pdf格式的圖像可以在我的應用程序中使用。 我正在使用UIImage-PDF( https://github.com/mindbrix/UIImage-PDF )類別在我的應用程序中將pdf顯示為圖像。 我正在使用此代碼
imageView = [[ UIImageView alloc ] initWithFrame:CGRectMake(100, 200, 100, 100)];
創建一個imageView,然后添加這樣的圖像
[imageView setImage:[ UIImage imageWithPDFNamed:[NSString stringWithFormat:@"%@.pdf",imageName] atSize:CGSizeMake( 100, 100) ]];
它適用於方形圖像,問題是當寬度大於高度時。 圖像縮小了。 我想要的是,它應該根據高度調整圖像的寬度。 我怎樣才能做到這一點?
將Imageview的contentMode
設置為UIViewContentModeScaleAspectFit
:
imageView.contentMode = UIViewContentModeScaleAspectFit;
你需要使用
imageView.contentMode = UIViewContentModeScaleAspectFit;
要么
imageView.contentMode = UIControlContentHorizontalAlignmentFill
嘗試這個,
UIImage *image =[ UIImage imageWithPDFNamed:[[NSString stringWithFormat:@"%@.pdf",imageName]];
[imageView setImage:image atSize:CGSizeMake( img.size.width, img.size.height) ]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.