Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support UITableView.Appearance.SectionHeaderTopPadding #12973

Open
DavidHathway opened this issue Oct 12, 2021 · 4 comments
Open

Support UITableView.Appearance.SectionHeaderTopPadding #12973

DavidHathway opened this issue Oct 12, 2021 · 4 comments
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS
Milestone

Comments

@DavidHathway
Copy link

DavidHathway commented Oct 12, 2021

Suggested Addition

In XCode 13, the new sectionHeaderTopPadding property was added to UITableView objects for iOS 15+. While this property is now accessible directly in the UITableView class in the most recent update of Xamarin in Visual Studio, it is not possible to set the its default value across all UITableView objects using the UITableView.Appearance property, even though the equivalent is now available in XCode.

The reason I ask for this to be added is that the default value for this new property is non-zero, which means any UITableView objects will by default have ugly extra padding added on iOS 15 devices, and in applications with many UITableView objects it would be far simpler and safer to be able to set a default sectionHeaderTopPadding value for all of them in one place (e.g. in AppDelegate) rather than having to manually add lines of code to change that property for each one separately.

Environment

Xamarin.iOS and Xamarin.Mac SDK (in Visual Studio for Windows), currently v15.0.0.8

Example Code

In XCode 13 I can set the default sectionHeaderTopPadding value across the whole app to zero by putting the following Swift code in e.g. AppDelegate:

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = 0.0
}

I would like to be able to achieve the same in Xamarin (in Visual Studio for Windows) by being able to call e.g. (in C#):

if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0)) {
    UITableView.Appearance.SectionHeaderTopPadding = 0.0f;
}

which currently is not supported.

@chamons
Copy link
Contributor

chamons commented Oct 12, 2021

@DavidHathway

Could you try the following manual binding?

        [System.Runtime.InteropServices.DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
        public extern static void void_objc_msgSend_nfloat(IntPtr receiver, IntPtr selector, nfloat arg1);

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            void_objc_msgSend_nfloat(UITableView.Appearance.Handle, ObjCRuntime.Selector.GetHandle("setSectionHeaderTopPadding:"), 0);

in your app, and see if it works. I don't have a table view app handy to see if it works (but it doesn't crash at least).

@chamons chamons added bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS labels Oct 12, 2021
@chamons chamons added this to the Future milestone Oct 12, 2021
@DavidHathway
Copy link
Author

@chamons Thanks for your response. I ran your void_objc_msgSend_nfloat() call in AppDelegate's FinishedLaunching() method, and it appears to have done the trick. That will make a good workaround for now – much appreciated.

@miszu
Copy link
Contributor

miszu commented Apr 21, 2022

Is there a plan to include this new UITableView.Appearance.SectionHeaderTopPadding = 0.0f property in Xamarin bindings? :)

@yaliashkevich
Copy link
Contributor

Is there a plan to include this new UITableView.Appearance.SectionHeaderTopPadding = 0.0f property in Xamarin bindings? :)

Mostly likely it is not, sectionHeaderTopPadding is not marked with UI_APPEARANCE_SELECTOR in UITableView.h file, so "officially" it is not part of table appearance protocol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS
Projects
None yet
Development

No branches or pull requests

4 participants