Ich habe diese UICollectionViewController
Klassencode:Bild in Image Ausgabe Swift
class ViewController1: UICollectionViewController , UICollectionViewDelegateFlowLayout{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.collectionView?.backgroundColor = UIColor(white: 0.95, alpha: 1)
self.collectionView?.alwaysBounceVertical = true
collectionView?.registerClass(Cell.self, forCellWithReuseIdentifier: "cellid")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCellWithReuseIdentifier("cellid", forIndexPath: indexPath)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 100)
}
}
class Cell :UICollectionViewCell {
//var i : Int = 0
override init(frame: CGRect) {
super.init(frame: frame)
self.setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var namelabel : UILabel = {
let label = UILabel()
label.text = "test"
//label.font = UIFont.boldSystemFontOfSize(14)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var distanzalabel : UILabel = {
let label = UILabel()
label.text = "200KM"
//label.font = UIFont.boldSystemFontOfSize(14)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var imageV : UIImageView = {
let imageView = UIImageView()
//imageView.frame = CGRectMake(0, 0, 450 , 150);
imageView.image = UIImage(named: "2.jpg")
imageView.contentMode = .ScaleAspectFit
//imageView.clipsToBounds = true
imageView.backgroundColor = UIColor.greenColor()
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
var imageV1 : UIImageView = {
let imageView = UIImageView()
imageView.frame = CGRectMake(0, 0, 20 , 20);
imageView.image = UIImage(named: "User Male Filled.png")
imageView.contentMode = .ScaleAspectFit
//imageView.clipsToBounds = true
imageView.backgroundColor = UIColor.blackColor()
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
func setupViews(){
backgroundColor = UIColor.whiteColor()
self.addSubview(namelabel)
self.addSubview(distanzalabel)
self.addSubview(imageV)
self.addSubview(imageV1)
let lunghezza = self.frame.width
let result = lunghezza - 100
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[v0(\(lunghezza))]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-\(result)-[v0(30)]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV1]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-5-[v0(33)]-4-[v1]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV , "v1" : namelabel]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-5-[v0(33)]-4-[v1]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : imageV , "v1" : imageV1]))
}}
Mein Problem ist, dass, wenn ich diesen Code ausführen ich dieses:
http://postimg.org/image/jqwjt0o2f/
, wie Sie durch die sehen können Bild, die zwei Bilder sind zu klein respektieren die UIImageview Größe, und ich möchte, dass zum Beispiel, wenn ich die UIImageView
'Größe ist 30x30 das Bild füllt alle ImageView.
ich wählen Farbe für zwei Image für die Show Sie die wirkliche Größe von UIImageView
Wie löse ich dieses Problem?
Ich weiß nicht, ob ich Ihr Problem verstehe. Möchten Sie einfach den Inhaltsmodus ändern, damit das Bild hochskaliert wird? Wenn ja, überprüfen Sie die Content-Modus-Eigenschaft – Maik639
Mein Problem ist, dass: wenn Sie das Bild sehen, können Sie zum Beispiel das erste Bild (in der uiimageview mit grünem Hintergrund) nicht füllen die gesamte uiimaview – gianni
Ich möchte, dass die Bild passt sich an die Größe von uiimageview – gianni