Jelajahi Sumber

Better constraints in the home view

Iñigo Valentin 9 tahun lalu
induk
melakukan
91308200fa

+ 3 - 3
Section.xib

@@ -31,15 +31,15 @@
                             <fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
                             <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
                         </textView>
-                        <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="hhU-TV-XGc" userLabel="Content">
+                        <stackView autoresizesSubviews="NO" opaque="NO" contentMode="scaleAspectFit" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="hhU-TV-XGc" userLabel="Content">
                             <rect key="frame" x="0.0" y="27" width="355" height="620"/>
                             <color key="backgroundColor" red="0.59607843137254901" green="0.78431372549019607" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                         </stackView>
                     </subviews>
                     <color key="backgroundColor" red="0.59607843140000005" green="0.7843137255" blue="1" alpha="1" colorSpace="calibratedRGB"/>
                     <constraints>
-                        <constraint firstItem="mYX-eR-Wot" firstAttribute="bottom" secondItem="hhU-TV-XGc" secondAttribute="top" id="0JC-9a-fRi"/>
-                        <constraint firstItem="mYX-eR-Wot" firstAttribute="trailing" secondItem="hhU-TV-XGc" secondAttribute="trailing" id="4VF-IP-46O"/>
+                        <constraint firstItem="mYX-eR-Wot" firstAttribute="bottom" secondItem="hhU-TV-XGc" secondAttribute="top" id="0JC-9a-fRi" userLabel="Section_Title.bottom=Content.top"/>
+                        <constraint firstItem="mYX-eR-Wot" firstAttribute="trailing" secondItem="hhU-TV-XGc" secondAttribute="trailing" id="4VF-IP-46O" userLabel="Section_Title.trailing=Content.trailing"/>
                         <constraint firstItem="mYX-eR-Wot" firstAttribute="leading" secondItem="hhU-TV-XGc" secondAttribute="leading" id="5pZ-0J-Mc4"/>
                         <constraint firstItem="hhU-TV-XGc" firstAttribute="top" secondItem="e7S-aL-6Ed" secondAttribute="top" constant="27" id="GaL-O1-uum"/>
                         <constraint firstAttribute="trailing" secondItem="hhU-TV-XGc" secondAttribute="trailing" id="IEf-ra-MWR"/>

TEMPAT SAMPAH
app.xcodeproj/project.xcworkspace/xcuserdata/seavenois.xcuserdatad/UserInterfaceState.xcuserstate


+ 1 - 1
app/Base.lproj/Main.storyboard

@@ -63,7 +63,7 @@
                                 </collectionViewFlowLayout>
                                 <cells>
                                     <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="a4j-DF-epb" customClass="MenuCollectionViewCell" customModule="app" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="-3" width="100" height="50"/>
+                                        <rect key="frame" x="0.0" y="-2.5" width="100" height="50"/>
                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                         <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                             <rect key="frame" x="0.0" y="0.0" width="100" height="50"/>

+ 7 - 3
app/HomeView.swift

@@ -76,7 +76,8 @@ class HomeView: UIView {
 		//Populate sections
 		setUpPastActivities(context: moc, delegate: appDelegate, lang: lang, parent: pastActivitiesSection.getContentStack())
 		
-		pastActivitiesSection.resizeToFitSubviews()
+		
+		pastActivitiesSection.expandSection()
 		
 		//Always at the end: update scrollview
 		var h: Int = 0
@@ -85,7 +86,8 @@ class HomeView: UIView {
 			h = h + Int(view.frame.height) + 30 //Why 30?
 			print("curh: \(h)")
 		}
-		self.scrollView.contentSize.height = CGFloat(h);
+		// TODO: Calculate at the end
+		self.scrollView.contentSize.height = 1200// CGFloat(h);
 	}
 	
 	func getLanguage() -> String{
@@ -133,9 +135,11 @@ class HomeView: UIView {
 				title = r.value(forKey: "title_\(lang)")! as! String
 				text = r.value(forKey: "text_\(lang)")! as! String
 				print(title)
-				row.setTitle(text: "aa\(title)")
+				row.setTitle(text: title)
 				row.setText(text: text)
 				
+				print("Row height: \(row.frame.height)")
+				
 				parent.addArrangedSubview(row)
 				
 			}

+ 55 - 65
app/HomeView.xib

@@ -30,80 +30,70 @@
                 <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Poy-ba-9jX">
                     <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
                     <subviews>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="0.0" y="0.0" width="320" height="120"/>
+                        <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="gOz-rr-CeQ">
+                            <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
+                            <subviews>
+                                <view autoresizesSubviews="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ljm-NP-c4e" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="0.0"/>
+                                </view>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9nu-j1-wGI" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="0.0"/>
+                                </view>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FQo-nm-4Mo" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="0.0"/>
+                                </view>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uHa-Mu-U68" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="0.0"/>
+                                </view>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="v6A-Ya-esA" customClass="Section" customModule="app" customModuleProvider="target">
+                                    <rect key="frame" x="0.0" y="0.0" width="320" height="10"/>
+                                </view>
+                                <view autoresizesSubviews="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZk-r1-Tca" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="10" width="320" height="350"/>
+                                    <color key="backgroundColor" red="0.13929578989999999" green="0.4641384549" blue="0.33924696180000002" alpha="1" colorSpace="calibratedRGB"/>
+                                    <userDefinedRuntimeAttributes>
+                                        <userDefinedRuntimeAttribute type="color" keyPath="borderColor">
+                                            <color key="value" red="0.60846421630000003" green="0.58038871199999997" blue="0.12541175830000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        </userDefinedRuntimeAttribute>
+                                        <userDefinedRuntimeAttribute type="number" keyPath="borderWidth">
+                                            <real key="value" value="5"/>
+                                        </userDefinedRuntimeAttribute>
+                                    </userDefinedRuntimeAttributes>
+                                </view>
+                                <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dgk-s8-xje" customClass="Section" customModule="app">
+                                    <rect key="frame" x="0.0" y="360" width="320" height="120"/>
+                                </view>
+                            </subviews>
+                            <color key="backgroundColor" red="1" green="1" blue="0.42787000868055558" alpha="1" colorSpace="calibratedRGB"/>
                             <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.Location.height" id="4XI-rg-Du1"/>
+                                <constraint firstItem="fZk-r1-Tca" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="2Ly-H5-cg3"/>
+                                <constraint firstItem="dgk-s8-xje" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="Fns-iO-jXi"/>
+                                <constraint firstItem="v6A-Ya-esA" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="GUl-qy-hrg"/>
+                                <constraint firstItem="Ljm-NP-c4e" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="Hca-x5-ir8"/>
+                                <constraint firstItem="9nu-j1-wGI" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="JLF-kC-CR9"/>
+                                <constraint firstItem="dgk-s8-xje" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="Oy3-i3-zcd"/>
+                                <constraint firstItem="fZk-r1-Tca" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="UDc-t0-pJ0"/>
+                                <constraint firstItem="v6A-Ya-esA" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="Uaq-4u-NBS"/>
+                                <constraint firstItem="FQo-nm-4Mo" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="aWZ-5w-1ke"/>
+                                <constraint firstItem="FQo-nm-4Mo" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="azo-MK-F5R"/>
+                                <constraint firstItem="uHa-Mu-U68" firstAttribute="centerX" secondItem="gOz-rr-CeQ" secondAttribute="centerX" id="i5O-1b-eCi"/>
+                                <constraint firstItem="uHa-Mu-U68" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="ljo-DJ-9M1"/>
+                                <constraint firstItem="Ljm-NP-c4e" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="s8R-dV-4ju"/>
+                                <constraint firstItem="9nu-j1-wGI" firstAttribute="width" secondItem="gOz-rr-CeQ" secondAttribute="width" id="v1C-hQ-R98"/>
                             </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9nu-j1-wGI" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="0.0" y="120" width="320" height="120"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.Lablanca.height" id="B0a-14-gfY"/>
-                            </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="FQo-nm-4Mo" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="0.0" y="240" width="320" height="120"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.FActivity.height" id="AJi-J2-weg"/>
-                            </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uHa-Mu-U68" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="0.0" y="360" width="320" height="120"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.Blog.Height" id="bV3-sl-7SD"/>
-                            </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="v6A-Ya-esA" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="28" y="480" width="320" height="120"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.Gallery.Height" id="vSS-A6-4QV"/>
-                            </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fZk-r1-Tca" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="160" y="600" width="0.0" height="0.0"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.PActivity.height" id="6SU-vG-oBN"/>
-                            </constraints>
-                        </view>
-                        <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dgk-s8-xje" customClass="Section" customModule="app" customModuleProvider="target">
-                            <rect key="frame" x="83" y="600" width="320" height="15"/>
-                            <constraints>
-                                <constraint firstAttribute="height" constant="120" identifier="HomeView.Social.height" id="9Ea-4y-vjH"/>
-                            </constraints>
-                        </view>
+                        </stackView>
                     </subviews>
                     <constraints>
-                        <constraint firstItem="FQo-nm-4Mo" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="000-Cy-wsR"/>
-                        <constraint firstItem="Ljm-NP-c4e" firstAttribute="top" secondItem="Poy-ba-9jX" secondAttribute="top" identifier="HomeView.Location.Top" id="23E-en-DDi"/>
-                        <constraint firstItem="uHa-Mu-U68" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="4KD-jX-3eU"/>
-                        <constraint firstItem="dgk-s8-xje" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="5mi-n8-URM"/>
-                        <constraint firstItem="fZk-r1-Tca" firstAttribute="top" secondItem="v6A-Ya-esA" secondAttribute="bottom" id="63J-zm-eA8"/>
-                        <constraint firstItem="dgk-s8-xje" firstAttribute="top" secondItem="fZk-r1-Tca" secondAttribute="bottom" id="8YH-MM-1cR"/>
-                        <constraint firstItem="9nu-j1-wGI" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" identifier="HomeView.Lablanca.Width" id="D2d-eu-aQa"/>
-                        <constraint firstItem="fZk-r1-Tca" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="Db8-t5-Jgb"/>
-                        <constraint firstItem="dgk-s8-xje" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="J7B-uj-NKg"/>
-                        <constraint firstItem="Ljm-NP-c4e" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" identifier="HomeView.Location.Center" id="T2f-t6-8Ax"/>
-                        <constraint firstItem="Ljm-NP-c4e" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" identifier="HomeView.Location.Width" id="V7B-2e-Zlq"/>
-                        <constraint firstItem="v6A-Ya-esA" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="VCL-tk-qZ9"/>
-                        <constraint firstItem="FQo-nm-4Mo" firstAttribute="top" secondItem="9nu-j1-wGI" secondAttribute="bottom" id="ZV1-6F-w0q"/>
-                        <constraint firstItem="uHa-Mu-U68" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="aSc-0o-zFE"/>
-                        <constraint firstItem="uHa-Mu-U68" firstAttribute="top" secondItem="FQo-nm-4Mo" secondAttribute="bottom" id="ad9-hp-x4I"/>
-                        <constraint firstItem="FQo-nm-4Mo" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="aqE-NW-zTF"/>
-                        <constraint firstItem="9nu-j1-wGI" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" identifier="HomeView.Lablanca.Center" id="cWL-iF-ULd"/>
-                        <constraint firstItem="v6A-Ya-esA" firstAttribute="top" secondItem="uHa-Mu-U68" secondAttribute="bottom" id="hSf-46-xQk"/>
-                        <constraint firstItem="fZk-r1-Tca" firstAttribute="centerX" secondItem="Poy-ba-9jX" secondAttribute="centerX" id="iGW-Be-hEH"/>
-                        <constraint firstItem="9nu-j1-wGI" firstAttribute="top" secondItem="Ljm-NP-c4e" secondAttribute="bottom" identifier="HomeView.Lablanca.Top" id="pCk-kh-wha"/>
-                        <constraint firstItem="v6A-Ya-esA" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="r2z-Z1-yS5"/>
-                        <constraint firstItem="uHa-Mu-U68" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="rp2-BX-jNV"/>
+                        <constraint firstItem="gOz-rr-CeQ" firstAttribute="width" secondItem="Poy-ba-9jX" secondAttribute="width" id="Gw0-jw-ldE"/>
+                        <constraint firstItem="gOz-rr-CeQ" firstAttribute="top" secondItem="Poy-ba-9jX" secondAttribute="top" id="Hmx-ri-LqQ"/>
+                        <constraint firstItem="gOz-rr-CeQ" firstAttribute="leading" secondItem="Poy-ba-9jX" secondAttribute="leading" id="k5u-hr-4th"/>
                     </constraints>
                 </scrollView>
             </subviews>
             <color key="backgroundColor" red="0.70980392160000005" green="0.82745098039999998" blue="0.8980392157" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
             <constraints>
-                <constraint firstItem="Poy-ba-9jX" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" identifier="HomeView.Scroll.Width" id="91y-2B-LO2"/>
-                <constraint firstItem="Poy-ba-9jX" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" identifier="HomeView.Scroll.Top" id="Oqf-OH-F61"/>
-                <constraint firstItem="Poy-ba-9jX" firstAttribute="height" secondItem="iN0-l3-epB" secondAttribute="height" identifier="HomeView.Scroll.Height" id="j3N-FA-cWS"/>
+                <constraint firstItem="Poy-ba-9jX" firstAttribute="width" secondItem="iN0-l3-epB" secondAttribute="width" id="9SN-Tf-raC"/>
+                <constraint firstItem="Poy-ba-9jX" firstAttribute="height" secondItem="iN0-l3-epB" secondAttribute="height" id="TFG-sf-YY4"/>
             </constraints>
             <point key="canvasLocation" x="26" y="52"/>
         </view>

+ 1 - 1
app/RowHomePastActivities.swift

@@ -73,7 +73,7 @@ Extension of UIView to be formatted as sections.
 		v.addSubview(container)
 		
 		
-		
+		//v.sizeToFit()
 		
 	}
 	

+ 7 - 0
app/Section.swift

@@ -61,6 +61,13 @@ class Section: UIView {
 		title.text = text
 	}
 	
+	func expandSection(){
+		print("Bounds: \(self.bounds)")
+		print("Frame: \(self.frame)")
+		print("Subviews: \(self.subviews)")
+		//sizeToFit()
+	}
+	
 	func addEntry(view : UIView){
 		let lbl = UILabel()
 		lbl.text = "ABBA"