swiftui grid
1.0.0
Swiftui Grid View Layout مع أنماط مخصصة.
افتح GridDemo.xcodeproj لمزيد من الأمثلة لنظام التشغيل iOS و MacOS و WatchOS و TVOS

ScrollView {
Grid ( colors ) {
Rectangle ( )
. foregroundColor ( $0 )
}
}
. gridStyle (
ModularGridStyle ( columns : . min ( 100 ) , rows : . fixed ( 100 ) )
)
ScrollView {
Grid ( 1 ... 69 , id : . self ) { index in
Image ( " ( index ) " )
. resizable ( )
. scaledToFit ( )
}
}
. gridStyle (
StaggeredGridStyle ( . horizontal , tracks : 8 , spacing : 4 )
) يتيح لك إعداد المسارات تخصيص سلوك الشبكة إلى حالة الاستخدام المحددة. كل من الشبكة المعيارية والمتداخلة تستخدم قيمة المسارات لحساب التصميم. في التصميم المعياري ، كل من الأعمدة والصفوف هما مسارات.
public enum Tracks : Hashable {
case count ( Int )
case fixed ( CGFloat )
case min ( CGFloat )
}يتم تقسيم الشبكة إلى كسور متساوية من الحجم المقدم من عرض الوالدين.
ModularGridStyle ( columns : 3 , rows : 3 )
StaggeredGridStyle ( tracks : 8 )يتم إصلاح حجم العنصر بعرض أو ارتفاع محدد.
ModularGridStyle ( columns : . fixed ( 100 ) , rows : . fixed ( 100 ) )
StaggeredGridStyle ( tracks : . fixed ( 100 ) )autolayout احترام عرض عنصر دقيقة أو ارتفاع.
ModularGridStyle ( columns : . min ( 100 ) , rows : . fixed ( 100 ) )
StaggeredGridStyle ( tracks : . min ( 100 ) ) احصل على حجم العنصر والموضع مع التفضيلات
struct CardsView : View {
@ State var selection : Int = 0
var body : some View {
ScrollView {
Grid ( 0 ..< 100 ) { number in
Card ( title : " ( number ) " )
. onTapGesture {
self . selection = number
}
}
. padding ( )
. overlayPreferenceValue ( GridItemBoundsPreferencesKey . self ) { preferences in
RoundedRectangle ( cornerRadius : 16 )
. strokeBorder ( lineWidth : 4 )
. foregroundColor ( . white )
. frame (
width : preferences [ self . selection ] . width ,
height : preferences [ self . selection ] . height
)
. position (
x : preferences [ self . selection ] . midX ,
y : preferences [ self . selection ] . midY
)
. animation ( . linear )
}
}
}
} لا تتردد في المساهمة عبر طلب الشوكة/السحب لإتقان فرع. إذا كنت ترغب في طلب ميزة أو الإبلاغ عن خطأ ، يرجى بدء مشكلة جديدة.
إذا وجدت هذا المشروع مفيدًا ، فيرجى التفكير في أن أصبح راعي جيثب.