0Pricing
Objective-C iOS Development for Legacy & Enterprise Apps · Ders

NSLayoutConstraint ile Auto Layout

Görünümlerin farklı cihaz ve yönlerde doğru biçimde yeniden boyutlanması için Auto Layout kısıtlarını kullanarak kod içinde uyarlanabilir UIKit arayüzleri oluşturun.

NSLayoutConstraint ile Auto Layout, CoddyKit'te ücretsiz bir Objective-C iOS Development for Legacy & Enterprise Apps dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Objective-C iOS Development for Legacy & Enterprise Apps öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Objective-C iOS Development for Legacy & Enterprise Apps kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Auto Layout?

Hardcoded frames break on different screen sizes and rotations. Auto Layout describes relationships between views — constraints — and the system computes the right frames at runtime.

Constraints Describe Rules

A constraint is a linear equation: one attribute equals a multiple of another plus a constant. For example, a button's leading edge equals its superview's leading edge plus 20 points.

Disabling Autoresizing Masks

When adding constraints in code, you must first turn off the old autoresizing system on the view, or constraints will conflict.

label.translatesAutoresizingMaskIntoConstraints = NO;

Creating a Constraint

The classic API is NSLayoutConstraint constraintWithItem:. It is verbose but explicit.

NSLayoutConstraint *c =
  [NSLayoutConstraint constraintWithItem:label
    attribute:NSLayoutAttributeLeading
    relatedBy:NSLayoutRelationEqual
    toItem:self.view
    attribute:NSLayoutAttributeLeading
    multiplier:1.0 constant:20];

Activating Constraints

A constraint does nothing until activated. Use activateConstraints: to turn an array of them on at once.

[NSLayoutConstraint activateConstraints:@[c]];

Anchor API

Modern UIKit offers a cleaner anchor syntax. Each view exposes anchors like leadingAnchor and topAnchor.

[label.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:20].active = YES;
[label.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:40].active = YES;

Width and Height

Constrain size directly with dimension anchors.

[label.widthAnchor constraintEqualToConstant:200].active = YES;
[label.heightAnchor constraintEqualToConstant:44].active = YES;

Safe Area Layout Guide

Pin views to the safeAreaLayoutGuide so content stays clear of notches, status bars, and home indicators.

[label.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;

Constraint Priorities

Every constraint has a priority from 1 to 1000. When constraints conflict, lower-priority ones yield. Required constraints are 1000; flexible ones use values like 750.

c.priority = UILayoutPriorityDefaultHigh; // 750

Intrinsic Content Size

Views like labels and buttons report an intrinsic content size based on their text. You often only need to pin position, letting the view size itself.

Debugging Layout

Conflicts print warnings to the console listing the fighting constraints. Use the View Hierarchy Debugger in Xcode to inspect frames and constraints visually.

Quick Check

Test your Auto Layout knowledge.

Recap

You learned Auto Layout in UIKit:

  • Constraints express relationships, not fixed frames
  • Set translatesAutoresizingMaskIntoConstraints = NO
  • Create with NSLayoutConstraint or the cleaner anchor API
  • Activate constraints and pin to the safe area
  • Use priorities and intrinsic size for flexible layouts

Auto Layout makes legacy UIs adapt to every device.

Sıkça Sorulan Sorular

“NSLayoutConstraint ile Auto Layout” dersi ücretsiz mi?

Evet — “NSLayoutConstraint ile Auto Layout” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Objective-C iOS Development for Legacy & Enterprise Apps kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Objective-C iOS Development for Legacy & Enterprise Apps kursu toplamda 4 dersten oluşur.

“NSLayoutConstraint ile Auto Layout” dersinde ne öğreneceğim?

Görünümlerin farklı cihaz ve yönlerde doğru biçimde yeniden boyutlanması için Auto Layout kısıtlarını kullanarak kod içinde uyarlanabilir UIKit arayüzleri oluşturun. Objective-C iOS Development for Legacy & Enterprise Apps ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Objective-C iOS Development for Legacy & Enterprise Apps öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Objective-C iOS Development for Legacy & Enterprise Apps, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“NSLayoutConstraint ile Auto Layout” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Objective-C iOS Development for Legacy & Enterprise Apps dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Objective-C iOS Development for Legacy & Enterprise Apps dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. UIView ve UIViewController
  2. Yaygın Kullanıcı Arayüzü Denetimleri ve Olaylar
  3. Tablo Görünümleri ve Koleksiyon Görünümleri
  4. NSLayoutConstraint ile Auto Layout
← Objective-C iOS Development for Legacy & Enterprise Apps Sayfasına Dön